Pagini recente » Cod sursa (job #2597323) | Cod sursa (job #1616499) | Cod sursa (job #308661) | Cod sursa (job #1612020) | Cod sursa (job #3278830)
#include <fstream>
#include <iostream>
#include <numeric>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int dad[100005];
int find(int x)
{
if (dad[x] == x)
return x;
return dad[x] = find(dad[x]);
}
int main()
{
int n, m;
fin >> n >> m;
iota(dad + 1, dad + n + 1, 1);
int c, x, y;
while (m--)
{
fin >> c >> x >> y;
int nx = find(x);
int ny = find(y);
if (c == 1)
{
if (ny > nx)
{
dad[ny] = nx;
}
else
{
dad[nx] = ny;
}
}
else
{
if (nx == ny)
{
fout << "DA\n";
}
else
{
fout << "NU\n";
}
}
}
return 0;
}