Pagini recente » Cod sursa (job #791622) | Cod sursa (job #3284981) | Cod sursa (job #1841408) | Cod sursa (job #2641223) | Cod sursa (job #2819179)
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
const int N=1e5+1;
int n,m;
int root[N];
int find_root(int x){
while(root[x]!=x)
x=root[x];
return x;
}
int main()
{
cin>>n>>m;
for(int i=1; i<=n; i++)
root[i]=i;
for(int i=1; i<=m; i++){
int c,x,y;
cin>>c>>x>>y;
if(c==1){
int a=find_root(x),b=find_root(y);
root[b]=a;
}
else{
int a=find_root(x), b=find_root(y);
if(a==b)
cout<<"DA\n";
else
cout<<"NU\n";
}
}
return 0;
}