Pagini recente » Cod sursa (job #1237321) | Cod sursa (job #2935624)
#include <fstream>
#include <vector>
using namespace std;
vector<int> tata;
int n, m, cod, x, y;
void radacina() {
while (tata[x] != x)
x = tata[x];
while (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[x] = y;
else
if (x == y)
fout << "DA\n";
else
fout << "NU\n";
m--;
}
fin.close();
fout.close();
return 0;
}