Pagini recente » Cod sursa (job #916367) | Cod sursa (job #1162927) | Cod sursa (job #1414022) | Cod sursa (job #2549274) | Cod sursa (job #2618201)
#include <bits/stdc++.h>
using namespace std;
vector <int> ind;
int n, m;
int root(int x) {
if(ind[x] == x) {
return x;
}
return (ind[x] = root(ind[x]));
}
void fabricaDeUnire(int x, int y) {
ind[root(y)] = root(x);
}
int main() {
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
scanf("%d%d", &n, &m);
for(int i = 0; i < n; ++i) {
ind.push_back(i);
}
for(int i = 0; i < m; ++i) {
int op, x, y;
scanf("%d%d%d", &op, &x, &y);
if(op == 1) {
fabricaDeUnire(x, y);
} else {
if(root(x) == root(y)) {
printf("DA\n");
} else {
printf("NU\n");
}
}
}
return 0;
}