Pagini recente » Cod sursa (job #675882) | Cod sursa (job #2797421) | Cod sursa (job #472683) | Cod sursa (job #235138) | Cod sursa (job #1810755)
#include <bits/stdc++.h>
#define ll long long
#define lli long long int
#define endl "\n"
using namespace std;
int t[100001],h[100001];
void unionf(int x, int y){
if(h[x] > h[y])
t[y] = x;
else
t[x] = y;
if(h[x] == h[y])
h[y]++;
}
int find(int x){
while(t[x] != x){
x = t[x];
}
return(x);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
int n,m;
cin >> n >> m;
for(int i=1;i<=n;i++)
t[i] = i;
for(int i=0;i<m;i++){
int tp, a, b;
cin >> tp >> a >> b;
if(tp == 1){
int root0, root1;
root0 = find(a);
root1 = find(b);
if(root0 != root1)
unionf(root0, root1);
} else {
int root0, root1;
root0 = find(a);
root1 = find(b);
if(root0 == root1)
cout << "DA" << endl;
else
cout << "NU" << endl;
}
}
return(0);
}