Pagini recente » Cod sursa (job #1481847) | Cod sursa (job #2234276) | Cod sursa (job #2391833) | Cod sursa (job #1223471) | Cod sursa (job #2468378)
#include <stdio.h>
int t[100001];
int findt( int x ) {
if ( t[x] == x )
return x;
t[x] = findt( t[x] );
return t[x];
}
int main(){
FILE *fin, *fout;
fin = fopen( "disjoint.in", "r" );
fout = fopen( "disjoint.out", "w" );
int n, m, i, op, x, y, tatax, tatay;
fscanf( fin, "%d%d", &n, &m );
for ( i = 1; i <= n; i++ )
t[i] = i;
for ( i = 0; i < m; i++ ) {
fscanf( fin, "%d%d%d", &op, &x, &y );
if ( op == 1 ) {
tatax = findt( x );
tatay = findt( y );
t[tatax] = tatay;
}
else if ( findt( x ) == findt( y ) )
fprintf( fout, "DA\n" );
else
fprintf( fout, "NU\n" );
}
fclose( fin );
fclose( fout );
return 0;
}