Pagini recente » Cod sursa (job #2837352) | Cod sursa (job #2182103) | Cod sursa (job #1538841) | Cod sursa (job #1972354) | Cod sursa (job #1320138)
#include <fstream>
#include <algorithm>
#define NMAX 100005
using namespace std;
ifstream in ( "disjoint.in" );
ofstream out ( "disjoint.out" );
int N , M ;
int Father[NMAX];
int Find ( int X ){
int i , j , R;
for( R = Father[X] ; R!=Father[R] ; R = Father[R] );
return R;
}
void Unite ( int X , int Y ){
Father[X] = Y ;
return ;
}
int main ( void ){
int i , j ;
in >> N >> M ;
for ( i = 1 ; i <= N ; ++i )
Father[i] = i ;
for ( i = 1 ; i <= M ; ++i ){
int type , x , y;
in >> type >> x >> y;
if ( type == 1 )
Unite ( Find(x) , Find(y) );
else out << ( Find(x) != Find(y) ? "NU" : "DA" );
}
return 0;
}