Pagini recente » Cod sursa (job #2807549) | Cod sursa (job #2495529) | Cod sursa (job #1644832) | Cod sursa (job #883053) | Cod sursa (job #3191736)
#include <bits/stdc++.h>
using namespace std;
string file = "disjoint";
ifstream fin(file + ".in");
ofstream fout(file + ".out");
int t[100001], n, m;
int root(int x) {
if (t[x] == x)
return x;
return t[x] = root(t[x]);
}
inline void unit(int x, int y) {
x = root(x);
y = root(y);
if (x != y)
t[x] = y;
}
int main() {
fin >> n >> m;
for (int i = 1; i <= n; i++)
t[i] = i;
for (int i = 1; i <= m; i++) {
int type, x, y;
fin >> type >> x >> y;
if (type == 1)
unit(x, y);
else
fout << (root(x) == root(y) ? "DA\n" : "NU\n");
}
return 0;
}