Pagini recente » Cod sursa (job #2498437) | Cod sursa (job #1345587) | Cod sursa (job #156297) | Cod sursa (job #2403582) | Cod sursa (job #2450061)
#include <cstdio>
using namespace std;
const int N = (int) 1e5 + 7;
int n, m;
int t[N];
int gami(int x) {
if (t[x] == x) {
return x;
} else {
return t[x] = gami(t[x]);
}
}
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 i = 1; i <= m; i++) {
int o, x, y;
scanf("%d %d %d", &o, &x, &y);
x = gami(x);
y = gami(y);
bool ok = (x != y);
if (o == 1 && ok) {
t[x] = y;
}
if (o == 2) {
if (ok) {
printf("NU\n");
} else {
printf("DA\n");
}
}
}
return 0;
}