Pagini recente » Cod sursa (job #3188233) | Cod sursa (job #303262) | Cod sursa (job #1714426) | Cod sursa (job #3269431) | Cod sursa (job #2847777)
#include <fstream>
#define NMAX 100000
using namespace std;
int parent[NMAX + 1];
int root (int child){
if (child == parent[child])
return child;
return parent[child] = root (parent[child]);
}
int main(){
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int n, t, type, op1, op2;
fin >> n >> t;
for (int i = 0; i < n; i++){
parent[i] = i;
}
while (t--){
fin >> type >> op1 >> op2;
if (type == 1)
parent[root(op2)] = root (op1);
else {
if (root (op1) == root(op2))
fout << "DA";
else
fout << "NU" ;
fout << "\n";
}
}
return 0;
}