Pagini recente » Cod sursa (job #1685108) | Cod sursa (job #492264) | Cod sursa (job #2677318) | Cod sursa (job #2696683) | Cod sursa (job #555660)
Cod sursa(job #555660)
#include<stdio.h>
using namespace std;
int n,m,tata[100001];
void read()
{
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++)
tata[i]=i;
}
void unite(int x,int y)
{tata[x]=y;}
int father(int x)
{
if(tata[x]!=x)
tata[x]=father(tata[x]);
return tata[x];
}
void solve()
{int x,y,tip,t1,t2;
for(int i=1;i<=m;i++)
{
scanf("%d %d %d",&tip,&x,&y);
t1=father(x);
t2=father(y);
if(tip==1)
unite(t1,t2);
else
{if(t1==t2)
printf("DA\n");
else
printf("NU\n");
}
}
}
int main()
{freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
read();
solve();
return 0;}