Pagini recente » Cod sursa (job #1720475) | Cod sursa (job #2733563) | Cod sursa (job #758871) | Cod sursa (job #870102) | Cod sursa (job #2468377)
#include <cstdio>
using namespace std;
const int NMAX=100000;
int t[NMAX+5];
void declare(int n)
{
int i;
for(i=1;i<=n;++i)
t[i]=i;
}
int findt(int x)
{
if(t[x]==x)
return x;
t[x]=findt(t[x]);
return t[x];
}
void unite(int x,int y)
{
int t1,t2;
t1=findt(x);
t2=findt(y);
t[t2]=t1;
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
int n,m,i,c,x,y;
scanf("%d%d",&n,&m);
declare(n);
for(i=1;i<=m;++i)
{
scanf("%d%d%d",&c,&x,&y);
if(c==1)
unite(x,y);
else
{
if(findt(x)==findt(y))
printf("DA\n");
else
printf("NU\n");
}
}
return 0;
}