Pagini recente » Cod sursa (job #2197031) | Cod sursa (job #2319828) | Cod sursa (job #2642025) | Cod sursa (job #2621933) | Cod sursa (job #3293683)
#include <bits/stdc++.h>
using namespace std;
///aemi
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, Q;
int t[100005];
void Union(int x, int y)
{
t[x] = y;
}
int FindRoot(int x)
{
int y, rad = x;
while (t[rad] != 0)
rad = t[rad];
while (x != rad)
{
y = t[x];
t[x] = rad;
x = y;
}
return rad;
}
int main()
{
int op, x, y;
fin >> n >> Q;
while (Q--)
{
fin >> op >> x >> y;
if (op == 1) Union(FindRoot(x), FindRoot(y));
else fout << (FindRoot(x) == FindRoot(y) ? "DA\n" : "NU\n");
}
return 0;
}