Pagini recente » Cod sursa (job #74003) | Cod sursa (job #2946063) | Cod sursa (job #605384) | Cod sursa (job #768353) | Cod sursa (job #2734392)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int N = 100001;
int edges[N];
int findFather (int a) {
if (edges[a] == a)
return a;
findFather(edges[a]);
}
void reunion (int x, int y) {
int father_x = findFather(x);
int father_y = findFather(y);
edges[father_y] = father_x;
}
int main() {
int n, m;
fin >> n >> m;;
for (int i = 1; i <= n; i++)
edges[i] = i;
while (m--) {
int cod, x, y;
fin >> cod >> x >> y;
if (cod == 2) {
if (findFather(x) == findFather(y))
fout << "DA\n";
else
fout << "NU\n";
} else
reunion(x, y);
}
}