Pagini recente » Cod sursa (job #2539598) | Cod sursa (job #3232345) | Cod sursa (job #3231515) | Cod sursa (job #2311506) | Cod sursa (job #2658592)
#include <bits/stdc++.h>
#define NMAX 100001
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int t[NMAX];
int Find(int x) {
return x == t[x] ? x : t[x] = Find(t[x]);
}
void Union(int x, int y) {
t[Find(x)] = y;
}
int main() {
ifstream::sync_with_stdio(0);
fin.tie(0);
int N, M;
fin >> N >> M;
for (int i = 1; i <= N; ++i) {
t[i] = i;
}
for (int q, x, y; M; --M) {
fin >> q >> x >> y;
if (q == 1) {
Union(x, y);
} else {
fout << (Find(x) == Find(y) ? "DA" : "NU") << '\n';
}
}
return 0;
}