Pagini recente » Cod sursa (job #1355728) | Cod sursa (job #2703648) | Cod sursa (job #2706467) | Cod sursa (job #2516106) | Cod sursa (job #2354644)
#include<iostream>
#include<stdio.h>
using namespace std;
int v[100000];
int boss(int x){
if(v[x]==x)
return x;
return v[x]=boss(v[x]);
}
int unire(int x,int y){
int xmax,ymax;
xmax=boss(x);
ymax=boss(y);
v[xmax]=ymax;
}
int main() {
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
int n,m,i,cer,x,y;
cin>>n>>m;
for(i=1;i<=n;i++)
v[i]=i;
for(i=1;i<=m;i++){
cin>>cer>>x>>y;
if(cer==1)
unire(x,y);
else{
if(boss(x)==boss(y))
cout<<"DA"<<'\n';
else
cout<<"NU"<<'\n';
}
}
return 0;
}