Pagini recente » Cod sursa (job #1621854) | Cod sursa (job #1602331) | Cod sursa (job #209742) | Cod sursa (job #1223915) | Cod sursa (job #1863840)
#include <fstream>
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
unsigned int father (unsigned int node);
unsigned int N, M;
unsigned int code, x, y;
unsigned int tree[100001];
unsigned int X, Y;
unsigned int i;
int main ()
{
fin >> N >> M;
for (i=1; i<=N; i++)
tree[i] = i;
for (i=1; i<=M; i++)
{
fin >> code >> x >> y;
X = father(x);
Y = father(y);
if (code == 1)
tree[Y] = X;
else
if (X == Y)
fout << "DA\n";
else
fout << "NU\n";
}
return 0;
}
unsigned int father (unsigned int node)
{
if (node == tree[node])
return node;
else
return father(tree[node]);
}