Pagini recente » Cod sursa (job #369624) | Cod sursa (job #3300814) | Cod sursa (job #305543) | Cod sursa (job #3343170) | Cod sursa (job #3344675)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
const int NMAX = 100000;
int T[NMAX + 1];
int Find(int i)
{
if (T[i] == 0)
return i;
return T[i] = Find(T[i]);
}
inline void Union(int cx, int cy)
{
T[cy] = cx;
}
int main()
{
int N, M, op, x, y, cx, cy;
f>> N >> M;
while (M--)
{
f >> op >> x >> y;
cx = Find(x);
cy = Find(y);
if (op == 1)
{
if (cx != cy)
Union(cx, cy);
}
else
{
if (cx == cy)
g << "DA\n";
else
g << "NU\n";
}
}
return 0;
}