Pagini recente » Cod sursa (job #2469896) | Cod sursa (job #2319897) | Cod sursa (job #1608699) | Cod sursa (job #3293284) | Cod sursa (job #1615854)
#include <cstdio>
#define NMax 100005
using namespace std;
int n,m,rad[NMax],arbore[NMax],p,x,y;
int root(int x){
while(rad[x])
x = rad[x];
return x;
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i = 1; i <= m; ++i){
scanf("%d%d%d",&p,&x,&y);
if(p == 2){
if(root(x) == root(y))
printf("DA\n");
else
printf("NU\n");
}else{
rad[root(y)] = root(x);
}
}
return 0;
}