Cod sursa(job #3170038)
Utilizator | Data | 16 noiembrie 2023 18:08:58 | |
---|---|---|---|
Problema | Paduri de multimi disjuncte | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.62 kb |
#include <bits/stdc++.h>
using namespace std;
int t[100001];
int n, m;
int rad(int nod) {
if (t[nod] == 0) {
return nod;
}
return t[nod] = rad(t[nod]);
}
int main() {
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
int c, x, y;
cin >> c >> x >> y;
if (c == 1) {
t[rad(y)] = rad(x);
} else {
if (rad(x) == rad(y)) {
cout << "DA";
} else {
cout << "NU";
}
cout << "\n";
}
}
}