Pagini recente » Cod sursa (job #334883) | Cod sursa (job #444316) | Cod sursa (job #1075028) | Cod sursa (job #472016) | Cod sursa (job #2302664)
#include<stdio.h>
int n,m,y,z,p[100001],r[100001];
int F(int x)
{
for(;p[x]!=x;x=p[x]);
return x;
}
int main()
{
freopen("disjoint.in","r",stdin),freopen("disjoint.out","w",stdout),scanf("%d%d",&n,&m);
for(y=1;y<=n;y++)
p[y]=y;
while(m--)
{
scanf("%d%d%d",&n,&y,&z),y=F(y),z=F(z);
if(n==1)
{
if(r[y]>r[z])
p[z]=y;
else
p[y]=z;
if(r[y]==r[z])
r[z]++;
}
else
printf("%s\n",y==z?"DA":"NU");
}
}