Pagini recente » Cod sursa (job #1438143) | Cod sursa (job #2918604) | Cod sursa (job #3220074) | Cod sursa (job #619324) | Cod sursa (job #1142338)
#include<cstdio>
using namespace std;
int t[100],h[100];
int find(int x){
while(x!=t[x])
x=t[x];
return x;
}
void unifica(int x,int y){
if(h[x]>h[y])
t[y]=x;
else
if(h[x]<h[y])
t[x]=y;
else{
h[x]++;
t[y]=x;
}
}
int main(){
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
int i,n,m,x,y,tx,ty,cod;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++){
t[i]=i;
h[i]=1;
}
for(i=1;i<=m;i++){
scanf("%d%d%d",&cod,&x,&y);
tx=find(x);
ty=find(y);
if(cod==1)
unifica(tx,ty);
else
if(find(x)==find(y))
printf("DA\n");
else
printf("NU\n");
}
return 0;
}