Pagini recente » Cod sursa (job #1570781) | Cod sursa (job #1643879) | Cod sursa (job #2416300) | Cod sursa (job #2568419) | Cod sursa (job #624307)
Cod sursa(job #624307)
#include <iostream>
#include <stdio.h>
using namespace std;
int n,m,op,x,y;
int t[100010];
int f(int x)
{
if(t[x]==x)
return t[x];
return t[x]=f(t[x]);
}
void citire()
{
freopen("disjoint.in","r",stdin);
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++)
t[i]=i;
for(int i=1;i<=m;i++)
{
scanf("%d %d %d",&op,&x,&y);
if(op==1)
t[f(y)]=f(x);
else
{
if(f(x)==f(y))
cout << "DA\n";
else
cout << "NU\n";
}
}
}
int main()
{
freopen("disjoint.out","w",stdout);
citire();
return 0;
}