Pagini recente » Cod sursa (job #2639380) | Cod sursa (job #2870230) | Cod sursa (job #164243) | Cod sursa (job #1659864) | Cod sursa (job #2692626)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, m;
int t[100005];
void Union(int x, int y)
{
t[x] = y;
}
int Find(int x)
{
int rad, aux;
rad = x;
while (t[rad])
{
rad = t[rad];
}
while (t[x])
{
aux = t[x];
t[x] = rad;
x = aux;
}
return rad;
}
void Rezolvare()
{
int op, x, y;
fin >> n >> m;
for (int i = 1; i <= m; i++)
{
fin >> op >> x >> y;
x = Find(x);
y = Find(y);
if (op == 1)
{
Union(x, y);
}
else
{
if (x == y)
{
fout << "DA" << "\n";
}
else
{
fout << "NU" << "\n";
}
}
}
}
int main()
{
Rezolvare();
return 0;
}