Pagini recente » Cod sursa (job #3136380) | Cod sursa (job #2001162) | Cod sursa (job #3223336) | Cod sursa (job #3036544) | Cod sursa (job #2690791)
#include <bits/stdc++.h>
using namespace std;
int dad[100001];
int N, M, x, y, op;
void Files(){
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
}
int Find(int x){
if(dad[x] == 0) return x;
return dad[x] = Find(dad[x]);
}
void Merge(int x, int y){
if(x != y) dad[y] = x;
}
int main(){
Files();
scanf("%d%d", &N, &M);
while(M--){
scanf("%d%d%d", &op, &x, &y);
x = Find(x), y = Find(y);
if(op == 1) Merge(x, y);
if(op == 2) printf((x == y)? "DA\n" : "NU\n");
}
}