Pagini recente » Cod sursa (job #563357) | Monitorul de evaluare | Cod sursa (job #1953333) | Cod sursa (job #2330835) | Cod sursa (job #2738182)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int N_MAX = 1e5 + 5;
int N, M, op, x, y;
int comp[N_MAX];
int Find(int x)
{
if (comp[x] == x) {
return x;
}
comp[x] = Find(comp[x]);
return comp[x];
}
void Union(int x, int y)
{
comp[Find(x)] = Find(y);
}
int main()
{
fin >> N >> M;
for (int i = 1; i <= N; i++) {
comp[i] = i;
}
for (int i = 1; i <= M; i++) {
fin >> op >> x >> y;
if (op == 1) {
Union(x, y);
}
else {
if (Find(x) == Find(y)) {
fout << "DA\n";
}
else {
fout << "NU\n";
}
}
}
return 0;
}