Pagini recente » Cod sursa (job #1244371) | Cod sursa (job #2859659) | Cod sursa (job #1863047) | Cod sursa (job #1785888) | Cod sursa (job #2710544)
#include <fstream>
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int n, t[100001];
int Find ( int x ) {
int R = x;
while ( t[R] != 0 )
R = t[R];
if ( x != R )
t[x] = R;
return R;
}
void Union ( int x, int y ) {
t[ Find(y) ] = Find( x );
}
int main()
{
int m, cod, x, y;
fin >> n >> m;
while ( m-- ) {
fin >> cod >> x >> y;
if ( cod == 1 )
Union( x, y );
else {
if ( Find(x) == Find(y) )
fout << "DA\n";
else
fout << "NU\n";
}
}
return 0;
}