Pagini recente » Cod sursa (job #1598458) | Cod sursa (job #2724300) | Cod sursa (job #3196294) | Cod sursa (job #2138351) | Cod sursa (job #2039020)
#include <iostream>
#include <fstream>
#define NMAX 100005
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, m;
int p[NMAX];
int parinte(int nod)
{
if (p[nod] == nod)return nod;
return p[nod] = parinte(p[nod]);
}
void unire(int x, int y)
{
p[parinte(x)] = parinte(y);
}
int verif(int x, int y)
{
if (parinte(x) == parinte(y))
return 1;
return 0;
}
int main()
{
fin >> n >> m;
for (int i = 1; i <= n; i++)
p[i] = i;
for (int i = 1; i <= m; i++)
{
int op, x, y;
fin >> op >> x >> y;
if (op == 1)
unire(x, y);
else
{
if(verif(x, y) == 1)
fout << "DA\n";
else fout << "NU\n";
}
}
return 0;
}