Pagini recente » Cod sursa (job #1130950) | Cod sursa (job #891653) | Cod sursa (job #846372) | Cod sursa (job #409752) | Cod sursa (job #2848210)
#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";
fout << "\n";
}
}
return 0;
}