Pagini recente » Cod sursa (job #2676923) | Cod sursa (job #67783) | Cod sursa (job #2521923) | Cod sursa (job #908167) | Cod sursa (job #2157161)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int nMax = 100001;
int n;
int t[nMax];
void Union(int x, int y) {
t[y] = x;
}
int Find(int x) {
int aux, rad;
rad = x;
while(t[rad]) {
rad = t[rad];
}
while(t[x]) {
aux = t[x];
t[x] = rad;
x = aux;
}
return rad;
}
int main()
{
int x, y, q, op;
fin >> n >> q;
while(q--) {
fin >> op >> x >> y;
x = Find(x);
y = Find(y);
if (op == 1) {
if (x != y)
Union(x, y);
}
else {
if (x == y)
fout << "DA\n";
else fout << "NU\n";
}
}
return 0;
}