Pagini recente » Cod sursa (job #678112) | Cod sursa (job #884192) | Cod sursa (job #2565983) | Cod sursa (job #2938666) | Cod sursa (job #2947028)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int n, m;
int x, y, op;
vector < int > tata;
int getRoot(int &a) {
if (tata[a] == a) {
return a;
}
return getRoot(tata[a]);
}
int main() {
f >> n >> m;
tata.resize(n + 1);
for (int i = 1; i <= n; i++)
tata[i] = i;
for (int i = 0; i < m; i++)
{
f >> op >> x >> y;
if (op == 1) {
tata[getRoot(y)] = getRoot(x);
} else {
if (getRoot(x) == getRoot(y)) {
g << "DA" << '\n';
} else {
g << "NU" << '\n';
}
}
}
}