Pagini recente » Cod sursa (job #933070) | Cod sursa (job #1241322) | Cod sursa (job #1533251) | Cod sursa (job #3185894) | Cod sursa (job #2978858)
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e5 + 1;
int T[NMAX];
int root(int x) {
if(T[x] == 0)
return x;
else
return root(T[x]);
}
void unite(int x, int y) {
T[x] = root(y);
}
int same_root(int x, int y) {
return root(x) == root(y);
}
int main() {
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; i++) {
int c, x, y;
cin >> c >> x >> y;
if(c == 1)
unite(x, y);
else
cout << (same_root(x, y) ? "DA" : "NU");
}
return 0;
}