Pagini recente » Cod sursa (job #1627998) | Cod sursa (job #2549131) | Cod sursa (job #2168435) | Cod sursa (job #1711993) | Cod sursa (job #2935630)
#include <fstream>
#include <vector>
using namespace std;
vector<int> tata;
int n, m, cod, x, y;
void radacina() {
while (tata[x] != x || tata[y] != y) {
if (tata[x] != x) x = tata[x];
if (tata[y] != y) y = tata[y];
}
}
int main()
{
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
fin >> n >> m;
tata.resize(n+1);
for (int i = 1; i <= n; i++)
tata[i] = i;
while (m > 0) {
fin >> cod >> x >> y;
radacina();
if (cod == 1)
tata[y] = x;
else
if (x == y)
fout << "DA\n";
else
fout << "NU\n";
m--;
}
fin.close();
fout.close();
return 0;
}