Pagini recente » Cod sursa (job #2555191) | Cod sursa (job #1222674) | Cod sursa (job #476151) | Cod sursa (job #675144) | Cod sursa (job #973095)
Cod sursa(job #973095)
#include<stdio.h>
int t[100002],h[100002];
inline int tata(int x)
{
while(t[x]!=x)
x=t[x];
return x;
}
inline void update(int x,int y)
{
if(h[x]>h[y])
t[y]=x;
else
t[x]=y;
if(h[x]==h[y])
++h[y];
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
int n,m,i,c,x,y;
scanf("%d%d",&n,&m);
for(i=1;i<=n;++i)
{
t[i]=i;
h[i]=1;
}
for(i=1;i<=m;++i)
{
scanf("%d%d%d",&c,&x,&y);
if(c==1)
update(x,y);
else
{
if(tata(x)==tata(y))
printf("DA\n");
else
printf("NU\n");
}
}
return 0;
}