Pagini recente » Cod sursa (job #1033109) | Cod sursa (job #961220) | Cod sursa (job #1350214) | Cod sursa (job #1243222) | Cod sursa (job #2651282)
#include <fstream>
#define f in
#define g out
using namespace std;
ifstream in ( "disjoint.in" );
ofstream out( "disjoint.out" );
int n, m, op, x, y, rx, ry, i;
int t[100100];
int rad ( int a ){
while ( t[a] > 0)
a = t[a];
return a;
}
int main() {
f>>n>>m;
for ( i=1; i <= n; i++ )
t[i] = -1;
for ( ; m--; ){
f>>op>>x>>y;
rx = rad(x);
ry = rad(y);
if ( op == 1 ){
if ( t[rx] < t[ry] ){
t[rx] += t[ry];
t[ry] = rx;
} else {
t[ry] += t[rx];
t[rx] = ry;
}
continue;
}
if ( rx == ry )
g<<"DA\n";
else g<<"NU\n";
}
return 0;
}