#include<bits/stdc++.h>
using namespace std;
const int MAX=100004;
int p[MAX],rank1[MAX]={0};
void MAKESET(int n){
for(int i=1;i<=n;i++)
p[i]=i;
}
int FIND(int x){
if(p[x]!=x)
p[x]=FIND(p[x]);
return p[x];
}
void union1(int x,int y){
int rx=FIND(x);
int ry=FIND(y);
if(rx==ry)
return ;
if(rank1[ry]>rank1[rx]){
p[rx]=ry;
}
else if(rank1[rx]>rank1[ry]){
p[ry]=rx;
}
else{
p[ry]=rx;
rank1[rx]+=1;
}}
main()
{
int n,q,x,a,b,i,k=0;
cin>>n;
MAKESET(n);
cin>>q;
while(q--){
cin>>x>>a>>b;
if(x==0)
union1(a,b);
else{
if(p[a]==p[b])
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;}
}
}Asked by: Deepak_kumar_Shaw on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.