Pagini recente » Cod sursa (job #91818) | Cod sursa (job #1990423) | Cod sursa (job #760206) | Cod sursa (job #658260) | Cod sursa (job #3344168)
#include<iostream>
using namespace std;
#define NMAX 100001
#define da "DA\n"
#define nu "NU\n"
int n,m,root[NMAX];
int get_root(int x){
if(x==root[x])return x;
return (root[x]=get_root(root[x]));
}
void join(int x,int y){
x=get_root(x);
y=get_root(y);
root[x]=y;
}
bool joined(int x,int y){
return get_root(x)==get_root(y);
}
signed main(){
#ifndef LOCAL
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#endif // LOCAL
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
cin>>n>>m;
for(int i=1;i<=n;++i)root[i]=i;
for(;m;--m){
int op,x,y;
cin>>op>>x>>y;
if(op-1){
cout<<(joined(x,y)?da:nu);
}else{
join(x,y);
}
}
return 0;
}