Pagini recente » Cod sursa (job #663736) | Cod sursa (job #2410444) | Cod sursa (job #289393) | Cod sursa (job #1084562) | Cod sursa (job #2936001)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
vector <int> tata, nivel;
int radacina(int nod) {
while (tata[nod])
nod = tata[nod];
return nod;
}
void uneste(int x, int y) {
tata[y] = x;
}
int main() {
int n, m, cod, x, y;
fin >> n >> m;
tata.resize(n + 1);
nivel.resize(n + 1);
for (int i = 1; i <= m; ++i) {
fin >> cod >> x >> y;
if (cod == 1) {
uneste(radacina(x), radacina(y));
}
else {
if (radacina(x) == radacina(y))
fout << "DA\n";
else
fout << "NU\n";
}
}
fin.close();
fout.close();
return 0;
}