Pagini recente » Istoria paginii runda/preoji2010_contest/clasament | Cod sursa (job #227988) | Cod sursa (job #1134269) | Cod sursa (job #205909) | Cod sursa (job #2979856)
/// [A][M][C][B][N] ///
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const char sp = ' ', nl = '\n';
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int nmax = 1e5;
int p[nmax + 1]{0}, sz[nmax + 1]{0};
int find(int x) {
return p[x] == x ? x : (p[x] = find(p[x]));
}
void merge(int x, int y) {
x = find(x), y = find(y);
if (x == y) {
return;
}
if (sz[y] > sz[x]) {
swap(x, y);
}
p[y] = x;
sz[x] += sz[y];
}
bool connected(int x, int y) {
return find(x) == find(y);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
fin >> n >> m;
for (int i = 1; i <= n; ++i) {
p[i] = i, sz[i] = 1;
}
while (m--) {
int c, x, y;
fin >> c >> x >> y;
if (c == 1) {
merge(x, y);
}
else {
fout << (connected(x, y) ? "DA" : "NU") << nl;
}
}
}