Pagini recente » Cod sursa (job #1096958) | Cod sursa (job #1546026) | sandwich | Cod sursa (job #1800329) | Cod sursa (job #1857385)
#include <fstream>
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
unsigned int father (unsigned int x);
unsigned int N, M;
unsigned int cod, x, y;
unsigned int f[100001];
unsigned int X, Y;
unsigned int i;
int main ()
{
fin >> N >> M;
for (i=1; i<=N; i++)
f[i] = i;
for (i=1; i<=M; i++)
{
fin >> cod >> x >> y;
X = father(x);
Y = father(y);
if (cod == 1)
f[Y] = X;
else
{
if (X == Y)
fout << "DA\n";
else
fout << "NU\n";
}
}
return 0;
}
unsigned int father (unsigned int x)
{
if (x == f[x])
return x;
else
return father(f[x]);
}