Pagini recente » Cod sursa (job #2470535) | Cod sursa (job #1255645) | Cod sursa (job #1728559) | Cod sursa (job #636206) | Cod sursa (job #1133057)
/*
Keep It Simple!
*/
#include<stdio.h>
#define MaxN 100005
int Tree[MaxN],n,nrop,type,x,y;
void Add(int x,int y)
{
Tree[x] = y;
}
int isRelation(int x,int y)
{
while(Tree[x]!=x) x = Tree[x];
while(Tree[y]!=y) y = Tree[y];
if(x == y)
return 1;
else
return 0;
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d%d",&n,&nrop);
for(int i=1;i<=n;i++) Tree[i] = i;
for(int i=1;i<=nrop;i++)
{
scanf("%d%d%d",&type,&x,&y);
if(type == 1)
Add(x,y);
else if(type == 2)
{
if( isRelation(x,y))
printf("DA\n");
else
printf("NU\n");
}
}
}