Pagini recente » Cod sursa (job #1218946) | Cod sursa (job #1824656) | Cod sursa (job #1727232) | Cod sursa (job #298746) | Cod sursa (job #2693986)
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int tata[100005], n, m;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int Find (int x)
{
int rad = x, y;
while (tata[rad] != 0)
rad = tata[rad];
while (x != rad)
{
y = tata[x];
tata[x] = rad;
x = y;
}
return rad;
}
void Union (int x, int y)
{
tata[x] = y;
}
void solve ()
{
int x, y, opt;
fin >> n >> m;
for (int i = 1; i <= m; i++)
{
fin >> opt >> x >> y;
x = Find (x);
y = Find (y);
if (opt == 1)
Union (x, y);
else
{
if (x == y)
fout << "DA\n";
else
fout << "NU\n";
}
}
}
int main()
{
solve();
return 0;
}