Pagini recente » Cod sursa (job #2365959) | Cod sursa (job #2356696) | Cod sursa (job #1313178) | Cod sursa (job #2663335) | Cod sursa (job #407256)
Cod sursa(job #407256)
#include<stdio.h>
#define Nmx 100002
int n,m;
int tata[Nmx];
int rad(int x)
{
int L=x;
while(tata[L]!=L)
L=tata[L];
while(tata[x]!=x)
{
int aux=tata[x];
tata[x]=L;
x=aux;
}
return L;
}
void unesc(int x,int y)
{
tata[rad(x)]=tata[rad(y)];
}
void citire()
{
scanf("%d%d",&n,&m);
int x,y,tip;
for(int i=1;i<=n;++i)
tata[i]=i;
for(int i=1;i<=m;++i)
{
scanf("%d%d%d",&tip,&x,&y);
if(tip==1)
unesc(x,y);
else if(rad(x)!=rad(y))
printf("NU\n");
else printf("DA\n");
}
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
citire();
return 0;
}