Pagini recente » Cod sursa (job #851110) | Cod sursa (job #276352) | Cod sursa (job #466277) | Cod sursa (job #1235096) | Cod sursa (job #2935623)
#include <fstream>
#include <vector>
using namespace std;
vector<int> tata;
int n, m, cod, x, y;
void radacina() {
while (tata[x] != 0)
x = tata[x];
while (tata[y] != 0)
y = tata[y];
}
int main()
{
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
fin >> n >> m;
tata.resize(n+1, 0);
//for (int i = 0; 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;
}