Pagini recente » Cod sursa (job #1388279) | Cod sursa (job #90734) | Cod sursa (job #2125347) | Cod sursa (job #1668394) | Cod sursa (job #984108)
Cod sursa(job #984108)
#include <stdio.h>
#define FOR(i, n) for(int i = 1; i <= n; ++i)
int F[100100];
int father(int x) {
return F[x] = (x == F[x] ? x : father(F[x]));
}
void unite(int x, int y) {
F[father(x)] = father(y);
}
int main() {
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
int N, M;
scanf("%d%d", &N, &M);
FOR(i, N) F[i] = i;
FOR(test, M) {
int op, x, y;
scanf("%d%d%d", &op, &x, &y);
if (op == 1)
unite(x, y);
else
printf("%s\n", father(x) == father(y) ? "DA" : "NU");
}
return 0;
}