Pagini recente » Cod sursa (job #1000197) | Cod sursa (job #1259460) | Cod sursa (job #1565476) | preONI 2008 - Runda 2 | Cod sursa (job #582328)
Cod sursa(job #582328)
#include<stdio.h>
#define dim 100100
int t[dim],r[dim],n,m;
int find ( int &x )
{
while ( x!=t[x] )
x = t[x] ;
return x;
}
void unite (int x, int y )
{
if ( r[x] > r[y] )
{
t[ x ] = y;
}
else
{
t[ y ] = x;
}
if ( r[x] == r[y] )
r[x]++ ;
}
void solve()
{
scanf("%d %d",&n,&m);
for(int i=1 ; i<=n;i++)
t[i] = i;
int x,y,t;
for(int k=1 ; k<=m ; k++)
{
scanf("%d %d %d",&t , &x , &y);
if ( t == 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;
}