跳到正文

个人记录

1221

zqrmon约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年8月16日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, q;
    cin >> n >> q;

    map<int, unordered_set<int>> follows;

    for (int i = 0; i < q; ++i) {
        int op, a, b;
        cin >> op >> a >> b;

        if (op == 1) {
            follows[a].insert(b);
        } else if (op == 2) {
            follows[a].erase(b);
            if (follows[a].empty()) {
                follows.erase(a);
            }
        } else if (op == 3) {
            if (follows[a].count(b) && follows[b].count(a)) {
                cout << "Yes\n";
            } else {
                cout << "No\n";
            }
        }
    }

    return 0;
}
原文