Pagini recente » Cod sursa (job #3360219) | Cod sursa (job #3360220) | Cod sursa (job #3360387) | Cod sursa (job #2399018) | Cod sursa (job #3360202)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
int tat[MAXN + 1];
int radRec ( int x ) {
if ( !tat[x] )
return x;
return tat[x] = radRec ( tat[x] );
}
void join ( int x , int y ) { tat[radRec ( x )] = radRec ( y ); }
string query ( int x , int y ) { return radRec ( x ) == radRec ( y ) ? "DA\n" : "NU\n"; }
int main () {
ifstream fin ( "disjoint.in" );
ofstream fout ( "disjoint.out" );
int n , m , i , cod , x , y;
fin >> n >> m;
for ( i = 0 ; i < m ; i++ ) {
fin >> cod >> x >> y;
if ( cod == 1 )
join ( x , y );
else
fout << query ( x , y );
}
return 0;
}