Pagini recente » Cod sursa (job #788941) | Cod sursa (job #805977) | Cod sursa (job #789913) | Istoria paginii runda/preoli9/clasament | Cod sursa (job #2525963)
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int DMAX = 1e5+10;
int tata[DMAX];
int n,m;
void unire(int x,int y);
int comp(int x);
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t,i,op,x,y;
fin>>n>>m;
for(i=1;i<=m;i++){
fin>>op>>x>>y;
if(op & 1){
if(comp(x) != comp(y))
unire(x,y);
}
else{
if(comp(x) == comp(y))
fout<<"DA\n";
else
fout<<"NU\n";
}
}
return 0;
}
int comp(int x){
int root = x;
while(tata[root])
root = tata[root];
int aux;
while (tata[x]) {
aux = tata[x];
tata[x] = root;
x = aux;
}
return root;
}
void unire(int x,int y){
x=comp(x);
y=comp(y);
tata[x]=y;
}