Cod sursa(job #2810923)
| Utilizator | Data | 30 noiembrie 2021 17:12:32 | |
|---|---|---|---|
| Problema | Paduri de multimi disjuncte | Scor | 40 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
int nodes[100001];
int last(int i) {
while (nodes[i]) {
i = nodes[i];
}
return i;
}
int main() {
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
int nr, operations;
cin >> nr >> operations;
while (operations--) {
int cod, x, y;
cin >> cod >> x >> y;
if (cod == 1) {
nodes[last(x)] = y;
}
else {
string answer[] = { "NU\n", "DA\n" };
cout << answer[last(x) == last(y)];
}
}
return 0;
}