Pagini recente » Cod sursa (job #2308327) | Cod sursa (job #1716960) | Cod sursa (job #2126073) | Cod sursa (job #2615506) | Cod sursa (job #1211623)
#include<cstdio>
using namespace std;
int tata[100001],i,n,m,x,y,op;
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d%d",&n,&m);
for (i=1;i<=n;++i) tata[i]=i;
for (i=1;i<=m;++i)
{
scanf("%d%d%d",&op,&x,&y);
if (op==1)
{
int j=x;
while(tata[j]!=j)
j=tata[j];
while (tata[y]!=y)
{
int val=tata[y];
tata[y]=j;
y=val;
}
tata[y]=j;
}
else
{
while (tata[y]!=y)
y=tata[y];
while (tata[x]!=x)
x=tata[x];
if (x==y) printf("DA\n");
else printf("NU\n");
}
}
return 0;
}