Pagini recente » Cod sursa (job #2360091) | Cod sursa (job #222528) | Cod sursa (job #2846959) | Cod sursa (job #2362443) | Cod sursa (job #1329769)
#include <iostream>
#include <fstream>
#define nmax 100005
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int v[nmax];
int n, m;
void quick_union(int x, int y){
if(v[x] > v[y]){
v[y]+= v[x];
v[x]= y;
}
else{
v[x]+= v[y];
v[y]= x;
}
}
int find_representative(int x){
if(v[x]<0) return x;
else{
v[x]= find_representative(v[x]);
return v[x];
}
}
int main(){
int op, x, y;
fin >> n >> m;
for(int i=1; i<=n; i++) v[i]= -1;
for(int i=1; i<=m; i++){
fin >> op >> x >> y;
if(op==1) quick_union(x, y);
else if(op==2 && find_representative(x) != find_representative(y)) fout << "\NU\n";
else fout << "DA\n";
}
return 0;
}