Pagini recente » Cod sursa (job #3218836) | Cod sursa (job #3286188) | Cod sursa (job #2185681) | Cod sursa (job #1634761) | Cod sursa (job #3300328)
#include <bits/stdc++.h>
using namespace std;
int tata[100005];
int getRoot(int node) {
while (node != tata[node]) {
node = tata[node];
}
return node;
}
void unite(int x, int y) {
int rootX = getRoot(x);
int rootY = getRoot(y);
tata[rootX] = rootY;
}
int main()
{
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
tata[i] = i;
}
for (int i = 1; i <= m; ++i) {
int type, x, y;
cin >> type >> x >> y;
if (type == 1) {
unite(x, y);
} else {
if (getRoot(x) == getRoot(y)) {
cout << "DA\n";
} else {
cout << "NU\n";
}
}
}
return 0;
}