Pagini recente » Cod sursa (job #2742359) | Cod sursa (job #767818) | Cod sursa (job #2566061) | Cod sursa (job #587900) | Cod sursa (job #2964536)
#include <fstream>
using namespace std;
ifstream cin ("disjoint.in");
ofstream cout ("disjoint.out");
int n,m, t[100001];
int tata (int x) {
if (x==t[x]) return x;
return tata (t[x]);
}
void reuniune (int x, int y) {
int tx=tata(x);
int ty=tata(y);
if (tx!=ty) t[ty]=tx;
}
int test (int x, int y) {
int tx=tata(x);
int ty=tata(y);
return tx==ty;
}
int main(){
cin>>n>>m;
for (int i=1; i<=n; i++) t[i]=i;
while (m--) {
int tip,x,y;
cin>>tip>>x>>y;
if (tip==1) reuniune (x,y);
else if (test(x,y)) cout<<"DA"<<'\n';
else cout<<"NU"<<'\n';
}
return 0;
}