Cod sursa(job #2908947)
Utilizator | Data | 7 iunie 2022 10:42:53 | |
---|---|---|---|
Problema | Paduri de multimi disjuncte | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.67 kb |
//3338
#include <fstream>
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
using namespace std;
int main() {
int n, m, v[501];
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;
}