Pagini recente » Cod sursa (job #1938726) | Cod sursa (job #3230200) | Cod sursa (job #225761) | Cod sursa (job #2788590) | Cod sursa (job #2550493)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, m, T[100001];
int Root(int x)
{
if (T[x] == 0)
return x;
int r = Root(T[x]);
T[x] = r;
return r;
}
int main()
{
fin >> n >> m;
for (int i = 1; i <= m; ++i)
{
int c, x, y;
fin >> c >> x >> y;
if (c == 1)
T[Root(x)] = Root(y);
else fout << (Root(x) == Root(y) ? "DA\n" : "NU\n");
}
return 0;
}