Pagini recente » Cod sursa (job #2136037) | Cod sursa (job #1319140) | Cod sursa (job #1092793) | Cod sursa (job #2419860) | Cod sursa (job #2819246)
#include <iostream>
#define NMAX 100005
using namespace std;
int n, m, t[NMAX];
int findRadac(int x) {
int radac = x;
while(radac != t[radac]) radac = t[radac];
while(x != t[x]) {
int crt = t[x];
t[x] = radac;
x = crt;
}
return radac;
}
int main()
{
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++i)
t[i] = i;
for(int op, x, y; m; --m) {
scanf("%d%d%d", &op, &x, &y);
if(op == 1)
t[findRadac(y)] = findRadac(x);
else
findRadac(x) == findRadac(y) ? printf("DA\n") : printf("NU\n");
}
return 0;
}