Pagini recente » Cod sursa (job #2429117) | Cod sursa (job #2964965) | Cod sursa (job #1031288) | Cod sursa (job #2133893) | Cod sursa (job #3125261)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("disjoint.in");
ofstream g ("disjoint.out");
const int nmax = 1e5 + 3;
int v[nmax], a, b, c, n, k;
int root(int nod)
{
if (v[nod] == nod)
return nod;
v[nod] = root(v[nod]);
return v[nod];
}
int main()
{
f >> n >> k;
for (int i = 1; i <= n; ++i)
v[i] = i;
while (k--)
{
f >> a >> b >> c;
if (a == 2)
{
if (root(b) == root(c))
g << "DA\n";
else
g << "NU\n";
}
v[root(b)] = root(c);
}
return 0;
}