Pagini recente » Cod sursa (job #1591357) | Cod sursa (job #2985630) | Cod sursa (job #1479574) | Cod sursa (job #249899) | Cod sursa (job #3192713)
#include <bits/stdc++.h>
using namespace std;
string __fname = "disjoint"; ifstream in (__fname + ".in"); ofstream out (__fname + ".out");
#define cin in
#define cout out
const int maxn = 1e5 + 1;
int p[maxn];
// int getdad (int x) {
// if (x == p[x]) return x;
// int rs = getdad(p[x]);
// p[x] = rs;
// return p[x];
// }
int getdad (int x) {
return p[x] = (p[x] == x ? x: getdad(p[x]));
}
void combine (int x, int y) {
x = getdad(x);
y = getdad(y);
p[x] = y;
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++){
p[i] = i;
}
while (m--) {
int t,x,y;
cin >> t >> x >> y;
if (t == 1) {
combine(x, y);
}
else {
if (getdad(x) == getdad(y)) {
cout << "DA\n";
}
else {
cout << "NU\n";
}
}
}
return 0;
}