Pagini recente » Cod sursa (job #3310993) | Cod sursa (job #3311044) | Cod sursa (job #354238) | Cod sursa (job #980445) | Cod sursa (job #3311045)
#include <fstream>
#include <vector>
#define nmax (int)(1e5+1)
using namespace std;
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
int n,q,t[nmax],task,x,y;
int get_root(int x){
if(t[x]>0)
return get_root(t[x]);
return x;
}
void join(int x,int y){
int rx=get_root(x),ry=get_root(y);
if(rx==ry)
return ;
if(t[rx]<t[ry])
swap(rx,ry);
t[rx]+=t[ry];
t[ry]=rx;
}
int main()
{
cin>>n>>q;
for(int i=1;i<=n;i++)
t[i]=-1;
while(q--){
cin>>task>>x>>y;
if(task==2){
if(get_root(x)!=get_root(y))
cout<<"NU\n";
else
cout<<"DA\n";
}else
join(x,y);
}
return 0;
}