求助
查看原帖
求助
973480
封禁用户楼主2024/8/25 19:00
#include<bits/stdc++.h>
using namespace std;
int n,q,f[10001];
int get(int x){
    if(f[x]==x) return x;
    return get(f[x]);
}
int main(){
    cin >> n >> q;
    for(int i=1;i<=n;i++) f[i]=i;
    while(q--){
        int x,y,z;
        cin >> z >> x >> y;
        if(z==1){
            if(get(x)!=get(y)) f[y]=x;
        }else{
            if(get(x)==get(y)) cout << "Y" << endl;
            else cout << "N" << endl;
        }
    }
    return 0;
}
2024/8/25 19:00
加载中...