Pagini recente » Cod sursa (job #2076408) | Cod sursa (job #3128163) | Cod sursa (job #1744722) | Cod sursa (job #2647585) | Cod sursa (job #1787222)
#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 x1, y1;
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;
x1 = father(x);
y1 = father(y);
if (cod == 1)
f[y1] = x1;
else
{
if (x1 == y1)
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]);
}