Pagini recente » Cod sursa (job #1230680) | Cod sursa (job #2871864) | Cod sursa (job #3178218) | Cod sursa (job #353685) | Cod sursa (job #2608558)
#include <fstream>
using namespace std;
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
int N,M, T[100100];
inline int root(int x) {
int tx=x, aux;
while(T[tx]!=tx)
tx=T[tx];
while(T[x]!=x) {
aux=T[x]; T[x]=tx; x=aux;
}
return x;
}
inline void onion(int x,int y) {
int rx=root(x), ry=root(y);
if(rx==ry)
return;
T[rx]=ry;
}
int main()
{
int x,y,op;
cin>>N>>M;
for(int i=1; i<=N; ++i)
T[i]=i;
for(int i=1; i<=M; ++i) {
cin>>op>>x>>y;
if(op==1)
onion(x,y);
else{
if(root(x)==root(y))
cout<<"DA"<<'\n';
else cout<<"NU"<<'\n';
}
}
return 0;
}