Pagini recente » Cod sursa (job #1091175) | Cod sursa (job #1646736) | Cod sursa (job #154008) | Cod sursa (job #1432331) | Cod sursa (job #3341921)
#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;
}