Pagini recente » Cod sursa (job #2228959) | Cod sursa (job #2980600) | Cod sursa (job #1896225) | Cod sursa (job #1414242) | Cod sursa (job #3139317)
#include <fstream>
using namespace std;
const int Nmax = 100005;
int father[Nmax], n , m;
int Find_root(int x) {
if(father[x] == 0) {
return x;
}
int root = Find_root(father[x]);
father[x] = root;
return root;
}
void Union(int x, int y) {
int r_x = Find_root(x);
int r_y = Find_root(y);
if(r_x != r_y) {
father[r_x] = r_y;
}
}
int main() {
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
fin >> n >> m;
while(m--) {
int op, x, y;
fin >> op >> x >> y;
if(op == 1) {
Union(x, y);
}
else {
if(Find_root(x) == Find_root(y)) {
fout << "DA\n";
}
else {
fout << "NU\n";
}
}
}
}