Pagini recente » Cod sursa (job #224112) | Cod sursa (job #3267106) | Cod sursa (job #668666) | Cod sursa (job #1149722) | Cod sursa (job #2450060)
#include <bits/stdc++.h>
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]);
}
}
string verdict[] = {"DA", "NU"};
int main() {
freopen ("disjoint.in", "r", stdin);
freopen ("disjoint.out", "w", stdout);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
t[i] = i;
}
for (int i = 1; i <= m; i++) {
int o, x, y;
cin >> o >> x >> y;
x = gami(x);
y = gami(y);
bool ok = (x != y);
if (o == 1 && ok) {
t[x] = y;
}
if (o == 2) {
cout << verdict[ok] << "\n";
}
}
return 0;
}