Pagini recente » Cod sursa (job #541471) | Cod sursa (job #1035914) | Cod sursa (job #503480) | Cod sursa (job #756983) | Cod sursa (job #562844)
Cod sursa(job #562844)
#include <stdio.h>
#define Dim 100001
int T[Dim];
int tata(int nod)
{
if(nod!=T[nod]) T[nod]=tata(T[nod]);
return T[nod];
}
int main()
{
int M,N,x,y,i,cod;
freopen("disjoint.in","r",stdin);
scanf("%d%d",&N,&M);
freopen("disjoint.out","w",stdout);
for(i=1;i<=N;i++) T[i]=i;
for(i=1;i<=M;i++)
{
scanf("%d%d%d",&cod,&x,&y);
x=tata(x);
y=tata(y);
if(cod==1) T[x]=y;
else x==y ? printf("DA\n") : printf("NU\n");
}
return 0;
}