Pagini recente » Cod sursa (job #1737914) | Cod sursa (job #1834868) | Cod sursa (job #1301571) | Cod sursa (job #1136748) | Cod sursa (job #1828435)
#include <fstream>
using namespace std;
unsigned int father (unsigned int x);
unsigned int N, M;
unsigned short int cod;
unsigned int x, y;
unsigned int f[100001];
unsigned int X, Y;
unsigned int i;
int main ()
{
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
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";
}
}
fin.close();
fout.close();
return 0;
}
unsigned int father (unsigned int x)
{
if (x == f[x])
return x;
else
return father(f[x]);
}