Cod sursa(job #3341921)
| Utilizator | Data | 21 februarie 2026 16:40:34 | |
|---|---|---|---|
| Problema | Paduri de multimi disjuncte | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.64 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
const int N_MAX = 100005;
int n, m, tip, x, y, v[N_MAX];
int top (int z) {
if (v[z] == 0)
return z;
int radacina = top(v[z]);
v[z] = radacina;
return radacina;
}
int main() {
fin >> n >> m;
while (m--) {
fin >> tip >> x >> y;
x = top(x);
y = top(y);
if (tip == 1)
v[x] = y;
else {
if (x == y)
fout << "DA\n";
else
fout << "NU\n";
}
}
return 0;
}
