Pagini recente » Cod sursa (job #1214863) | Cod sursa (job #994150) | Cod sursa (job #161553) | Cod sursa (job #1088061) | Cod sursa (job #1878803)
#include <iostream>
#include <fstream>
using namespace std;
int father[100001], height[100001];
int get_root(int x) {
if (father[x] == x)
return x;
father[x] = get_root(father[x]);
return father[x];
}
void join(int x, int y) {
int rootX = get_root(x);
int rootY = get_root(y);
father[rootY] = rootX;
}
int main() {
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
int n, m, x, y, o;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
father[i] = i;
height[i] = 1;
}
for (int i = 1; i <= m; ++i) {
cin >> o >> x >> y;
if (o == 1) {
join(x, y);
} else {
if (get_root(x) == get_root(y)) {
cout << "DA" << '\n';
} else {
cout << "NU" << '\n';
}
}
}
return 0;
}