Pagini recente » Cod sursa (job #2547087) | Cod sursa (job #2877031) | Cod sursa (job #1491442) | Cod sursa (job #2366171) | Cod sursa (job #2302660)
#include<stdio.h>
int n,m,x,y,z,c,d,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(x=1;x<=n;x++)
p[x]=x;
while(m--)
{
scanf("%d%d%d",&x,&y,&z);
if(x==1)
{
c=F(y),d=F(z);
if(r[c]>r[d])
p[d]=c;
else
p[c]=d;
if(r[c]==r[d])
r[d]++;
}
else
printf("%s\n",F(y)==F(z)?"DA":"NU");
}
}