Pagini recente » Cod sursa (job #2612356) | Cod sursa (job #1812335) | Cod sursa (job #2536586) | Cod sursa (job #2589662) | Cod sursa (job #2115762)
#include <iostream>
#include <cstdio>
using namespace std;
int n,m,t[100002];
int cod,x,y;
int cauttata(int l)
{
if(t[l]==0)
return l;
t[l]=cauttata(t[l]);
return t[l];
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d %d", &n, &m);
for(int i=0;i<m;++i)
{
scanf("\n%d %d %d", &cod, &x, &y);
if(cod==1)
{
int tx=cauttata(x),ty=cauttata(y);
t[tx]=ty;
}
else if(cod==2)
{
int tx=cauttata(x),ty=cauttata(y);
if(tx==ty)
cout<<"DA\n";
else
cout<<"NU\n";
}
}
return 0;
}