0%

APCS-好朋友

Code

#include <bits/stdc++.h>
#define int long long
using namespace std;

int p[1000000];
int find(int idx){
    while(idx!=p[idx]){
        idx = p[idx];//cout  << "get " << idx << endl;
    }
    return idx;
}

signed main() {
    typedef pair<int, int> pp;
    // DSU
    int N,M,Q;cin >> N >> M >> Q;
    for(int i=1;i<=N;i++)p[i]=i;
    while(M--){
        int a,b;cin >> a >> b;
        int idx = min(find(a),find(b));
        p[find(a)] = idx;
        p[find(b)] = idx;
    }

    /*for(int i=1;i<=N;i++){
        cout << i << ": " << p[i] << endl;
    }*/
    while(Q--){
        int a,b;cin >> a >> b;
        if(find(a) == find(b)){
            cout << ":)" << endl;
        } else {
            cout << ":(" << endl;
        }
    }
    return 0;
}