Pagini recente » Cod sursa (job #368115) | Cod sursa (job #473980) | Cod sursa (job #3206848) | Cod sursa (job #390703) | Cod sursa (job #403655)
Cod sursa(job #403655)
#include<stdio.h>
#define dim 100100
int n,m,t[dim],r[dim];
void unite(const int &x,const int &y)
{
if(r[x]<r[y])
t [ x ] = y ;
else
t [ y ] = x ;
if(r[x]==r[y])
++ r[x];
return ;
}
int find(int &x)
{
if( x != t[x] )
t[x] = find( t[x] ) ;
return t[ x ] ;
}
void solve()
{
int x,c,y;
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\n",&c,&x,&y);
if(c==1)
unite( find(x) , find(y) );
else
if(find(x) == find(y))
printf("DA\n");
else
printf("NU\n");
}
}
int main ()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
solve();
return 0;
}