Cod sursa(job #2908948)
| Utilizator | Data | 7 iunie 2022 10:44:34 | |
|---|---|---|---|
| Problema | Paduri de multimi disjuncte | Scor | 70 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.67 kb |
//3338
#include <fstream>
using namespace std;
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
int n, m, v[100005];
int main() {
cin >> n >> m;
for(int i = 1; i <= n; ++i) {
v[i] = i;
}
for(int i = 1; i <= m; ++i) {
int op, x, y;
cin >> op >> x >> y;
while(x != v[x]) {
x = v[x];
}
while(y != v[y]) {
y = v[y];
}
if(op == 1) {
v[x] = y; /// sau v[y] = x;
} else {
if(x == y) {
cout << "DA\n";
} else {
cout << "NU\n";
}
}
}
return 0;
}
