Pagini recente » Cod sursa (job #2150139) | Cod sursa (job #1943305) | Cod sursa (job #2638420) | Cod sursa (job #1216074) | Cod sursa (job #2115936)
#include <bits/stdc++.h>
using namespace std;
int v[100001];
int root(int x) {
if (v[x] == x || !v[x]) return x;
return v[x] = root(v[x]);
}
void join(int x, int y) {
v[root(x)] = root(y);
}
void query(int x, int y) {
if (root(x) == root(y))
cout << "DA\n";
else
cout << "NU\n";
}
int main()
{
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
int n, m;
cin >> n >> m;
int op, x, y;
for (int i = 0; i < m; i++) {
cin >> op >> x >> y;
if (op == 1)
join(x, y);
else {
query(x, y);
}
}
return 0;
}