Pagini recente » Cod sursa (job #771676) | Cod sursa (job #1814648) | Cod sursa (job #303982) | Cod sursa (job #1228780) | Cod sursa (job #3217488)
#include <iostream>
using namespace std;
#define NMAX 100000
int n, m;
int r[NMAX + 1];
int t[NMAX + 1];
int rad(int x) {
while (t[x] != 0) {
x = t[x];
}
return x;
}
void join(int x, int y) {
t[y] = x;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
cin >> n >> m;
for (int i = 1; i <= n; i += 1) {
r[i] = i;
t[i] = 0;
}
for (int i = 0; i < m; i += 1) {
int cod, x, y;
cin >> cod >> x >> y;
if (cod == 1) {
join(rad(x), rad(y));
} else {
if (rad(x) == rad(y)) {
cout << "DA\n";
} else {
cout << "NU\n";
}
}
}
return 0;
}