Pagini recente » Cod sursa (job #1822008) | Cod sursa (job #2252847) | Cod sursa (job #2860627) | Cod sursa (job #2477160) | Cod sursa (job #3164227)
#include <iostream>
#include <fstream>
using namespace std;
#define nmax 100003
int parinte[nmax];
int sef( int x ) {
if( parinte[x] == x )
return x;
return sef( parinte[x] );
parinte[x] = parinte[parinte[x]];
}
int main()
{
int n, q, i, t, x, y, a, b;
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
cin >> n >> q;
for( i = 1; i <= n; i++ )
parinte[i] = i;
for( i = 0; i < q; i++ ) {
cin >> t >> x >> y;
if( t == 1 ) {
b = sef(y);
parinte[x] = b;
}
else {
if( sef(x) == sef(y) )
cout << "DA\n";
else
cout << "NU\n";
}
}
return 0;
}