Pagini recente » Cod sursa (job #2620626) | Cod sursa (job #422811) | Cod sursa (job #3272810) | Cod sursa (job #1199716) | Cod sursa (job #2417338)
#include <stdio.h>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i = a; i < b; i++)
using namespace std;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
const int Nmax = 100555;
int N, M, q, x, y, a[Nmax];
int root(int x) {
if (a[x] == x) {
return x;
}
return a[x] = root(a[x]);
}
void join(int x, int y) {
int rx = root(x);
int ry = root(y);
a[rx] = a[ry] = min(rx, ry);
}
bool query(int x, int y) {
return root(x) == root(y);
}
int main(void) {
fin >> N >> M;
rep(i, N+1) { a[i] = i; }
while(M--) {
fin >> q >> x >> y;
if (q == 1) {
join(x, y);
} else if (q == 2) {
fout << (root(x) == root(y) ? "DA\n" : "NU\n" );
}
}
return 0;
}