Pagini recente » Cod sursa (job #1057381) | Cod sursa (job #1926693) | Cod sursa (job #1981303) | Cod sursa (job #888223) | Cod sursa (job #1142324)
#include<cstdio>
using namespace std;
int t[105],h[105],f[105];
int find_set(int x)
{
while(x!=t[x])
x=t[x];
return x;
}
void unifica(int x,int y)
{
if(h[x]>h[y])
t[y]=x;
else
if(h[x]<h[y])
t[x]=y;
else
{
h[x]++;
t[y]=x;
}
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
int n,m,i,op,x,y,tx,ty;
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",&op,&x,&y);
if(op==1)
{
tx=find_set(x);
ty=find_set(y);
unifica(tx,ty);
}
else
{
tx=find_set(x);
ty=find_set(y);
if(tx==ty)
printf("DA\n");
else
printf("NU\n");
}
}
}