GLACIERFS_ @ 2017-06-27 16:54:26
#include<iostream>
using namespace std;
int f[100001];
int n,m,p;
int find(int x){
if(x==f[x])return x;
else return f[x] = find(f[x]);
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)
f[i]=i;
int xx[10001],yy[10001];
for(int i=1;i<=m;i++){
cin>>p>>xx[i]>>yy[i];
if(p==2){
if(find(xx[i])==find(yy[i])){
cout<<"Y"<<endl;
}
else cout<<"N"<<endl;
}
else if(p==1){
int fa=find(xx[i]);
int fb=find(yy[i]);
f[fa]=fb;
}
}
return 0;
}
by tumult_2 @ 2017-07-08 17:05:38
200 000个点