Pagini recente » Cod sursa (job #335255) | Cod sursa (job #1525484) | Cod sursa (job #2019720) | Cod sursa (job #3150842) | Cod sursa (job #2090540)
#include <stdio.h>
#include <stdbool.h>
#define MAXN 100000
int t[MAXN+1];
void join(int x, int y) {
t[x] = tata(y);
}
int tata(int x) {
if(t[x] == x)
return x;
else
return t[x] = tata(t[x]);
}
bool query(int x, int y) {
return tata(x) == tata(y);
}
int main() {
int n, m, i, op, x, y;
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
scanf("%d%d", &n, &m);
for(i=1; i<=n; i++) t[i] = i;
for(i=1; i<=m; i++) {
scanf("%d%d%d", &op, &x, &y);
if(op == 1) {
join(x, y);
}
if(op == 2) {
if(query(x, y)) {
printf("DA\n");
} else {
printf("NU\n");
}
}
}
return 0;
}