Pagini recente » Cod sursa (job #1016295) | Cod sursa (job #2160477) | Cod sursa (job #1008437) | Cod sursa (job #1322319) | Cod sursa (job #2816264)
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int p[N];
int n;
int find(int x){
if(x==p[x]) return x;
int r=find(p[x]);
p[x]=r;
return r;
}
inline bool same(int x, int y){
return find(x)==find(y);
}
void join(int x, int y){
if(same(x,y)) return;
p[find(y)]=find(x);
}
int main(){
int m;
fin>>n>>m;
for(int i=1;i<=n;++i){
p[i]=i;
}
for(;m--;){
int op,x,y;
fin>>op;
fin>>x>>y;
if(op==1){
join(x,y);
}else{
fout<<(same(x,y)?"DA":"NU")<<"\n";
}
}
}