Pagini recente » Cod sursa (job #1117283) | Cod sursa (job #1681307) | Cod sursa (job #274242) | Cod sursa (job #1966409) | Cod sursa (job #2627921)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int N, M, cod, x, y, t[100000];
int Find(int i) {
if (t[i] == i)
return i;
return t[i] = Find(t[i]);
}
void Union(int i, int j) {
int ti, tj;
ti = Find(i);
tj = Find(j);
t[tj] = ti;
}
int main() {
fin >> N >> M;
for (int i = 0; i < N; i++) t[i] = i;
while (M--) {
fin >> cod >> x >> y;
x--, y--;
if (cod == 1) Union(x, y);
else {
int tx = Find(x),
ty = Find(y);
fout << ((tx == ty) ? "DA\n" : "NU\n");
}
}
fin.close();
fout.close();
return 0;
}