Pagini recente » Cod sursa (job #1014025) | Cod sursa (job #697847) | Cod sursa (job #1666032) | Cod sursa (job #1288490) | Cod sursa (job #2119150)
#include <bits/stdc++.h>
using namespace std;
int t[100010];
int arb(int x){
if (t[x]==x) return x;
else return arb(t[x]);
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
int n,m,i,p,x,y;
scanf("%d%d",&n,&m);
for (i=1;i<=n;i++) t[i]=i;
for (i=1;i<=m;i++){
scanf("%d%d%d",&p,&x,&y);
if (p==1&&x!=y){
t[arb(y)]=x;
}
else{
if (arb(x)==arb(y)) printf("DA\n");
else printf("NU\n");
}
}
return 0;
}