Pagini recente » Cod sursa (job #2327447) | Cod sursa (job #1256929) | Cod sursa (job #2060733) | Cod sursa (job #1315514) | Cod sursa (job #2848207)
#include <iostream>
#include <fstream>
using namespace std;
const int MAXN = 1e5;
ifstream fin( "disjoint.in" );
ofstream fout( "disjoint.out" );
int father[MAXN+1];
int findd( int x );
void unite( int x, int y ) {
int xx, yy;
xx = findd(x);
yy = findd(y);
if( xx != yy )
father[x] = y;
}
int findd( int x ) {
if( x == father[x] )
return x;
return father[x] = findd( father[x] );
}
int main() {
int n, m, i, op, x, y;
fin >> n >> m;
for( i = 1; i <= n; i++ )
father[i] = i;
for( i = 0; i < m; i++ ) {
fin >> op >> x >> y;
if( op == 1 )
unite( x, y );
else {
if( findd(x) == findd(y) )
fout << "DA";
else fout << "NU";
}
}
return 0;
}