Pagini recente » Cod sursa (job #2455684) | Cod sursa (job #35131) | Cod sursa (job #2778367) | Cod sursa (job #1675921) | Cod sursa (job #2302657)
#include<stdio.h>
int n,m,x,y,z,c,d,p[100001],r[100001];
int F(int i)
{
return p[i]==i?i:F(p[i]);
}
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");
}
}