Pagini recente » Cod sursa (job #1824790) | Cod sursa (job #509802) | Cod sursa (job #130755) | Cod sursa (job #2092942) | Cod sursa (job #2824216)
#include <iostream>
#include <climits>
#include <string>
#include <algorithm>
#include <fstream>
using namespace std;
const int NMAX = 100000;
int tata[1 + NMAX];
int main()
{
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int n, m;
in >> n >> m;
for (int i = 1; i <= n; i++)
{
tata[i] = i;
}
for (int i = 1; i <= m; i++)
{
int tipOperatie, a, b;
in >> tipOperatie >> a >> b;
if (tipOperatie == 2)
{
if (tata[a] == tata[b])
{
out << "DA" <<'\n';
}
else
out << "NU" << '\n';
}
else
{
int c = tata[b];
for (int j = 1; j <= n; j++)
{
if (tata[j] == c)
{
tata[j] = tata[a];
}
}
}
}
}