Pagini recente » Cod sursa (job #3259634) | Cod sursa (job #286201) | Borderou de evaluare (job #1569082) | Clasament foxoi | Cod sursa (job #2832513)
#include <fstream>
using namespace std;
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
int t[100001];
int sef(int x){
if (t[x]==x)
return x;
else
return sef(t[x]);
}
void unire(int x,int y){
t[sef(y)]=sef(x);
}
int main(){
int n,m,i,x,y,op;
cin>>n>>m;
for (i=1;i<=n;i++)
t[i]=i;
for (i=1;i<=m;i++) {
cin>>op>>x>>y;
if (op==1)
unire(x,y);
else if (sef(x)==sef(y))
cout<<"DA"<<endl;
else
cout<<"NU"<<endl;
}
return 0;
}