1 #include<cstdio> 2 3 using namespace std; 4 5 int max(int x,int y){ 6 if(x>y)return x;else return y; 7 } 8 9 int find(int); 10 11 int n,m,f,x,y,a,b; 12 int fa[10005],h[10005]; 13 14 int main(){ 15 scanf("%d%d",&n,&m); 16 for(int i=1;i<=n;i++){ 17 fa[i]=i; 18 h[i]=1; 19 } 20 for(int i=1;i<=m;i++){ 21 scanf("%d%d%d",&f,&x,&y); 22 a=find(x); 23 b=find(y); 24 if(f==1){ 25 if(h[a]<h[b]){ 26 fa[a]=b; 27 h[b]=max(h[b],h[a]+1); 28 } 29 else{ 30 fa[b]=a; 31 h[a]=max(h[a],h[b]+1); 32 } 33 } 34 else{ 35 if(a==b)printf("Y "); 36 else printf("N "); 37 } 38 } 39 40 return 0; 41 } 42 43 int find(int x){ 44 if(fa[x]==x)return x; 45 else return find(fa[x]); 46 }