Pagini recente » Cod sursa (job #1727428) | Cod sursa (job #237314) | Cod sursa (job #2844743) | Cod sursa (job #1692831) | Cod sursa (job #2843976)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int N_MAX = 100000;
int root[N_MAX + 1];
void unite(int a, int b) {
root[a] = root[b];
}
int findRoot(const int& x) {
if (x == root[x]) {
return x;
}
return root[x] = findRoot(root[x]);
}
int main() {
fin.tie(0);
int n, queries;
fin >> n >> queries;
for (int i = 1; i <= n; ++i) {
root[i] = i;
}
while (queries--) {
char type;
int x, y;
fin >> type >> x >> y;
if (type == '1') {
unite(findRoot(x), findRoot(y));
} else if (findRoot(x) == findRoot(y)) {
fout << "DA\n";
} else {
fout << "NU\n";
}
}
}