Pagini recente » Cod sursa (job #2389929) | Cod sursa (job #1121174) | Cod sursa (job #2286718) | Cod sursa (job #2024818) | Cod sursa (job #2939397)
#include <fstream>
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
const int NMAX = 1e5 + 5;
int Father[NMAX], N, M;
int getFather(int x)
{
if(Father[x] == 0)
return x;
Father[x] = getFather(Father[x]);
return Father[x];
}
int main()
{
int x, y, opType, rootX, rootY;
in >> N >> M;
for(int i = 1; i <= M; i++)
{
in >> opType >> x >> y;
rootX = getFather(x);
rootY = getFather(y);
if(opType == 1)
{
if(rootX != rootY)
Father[rootX] = rootY;
}
else
{
if(rootX == rootY)
out << "DA\n";
else
out << "NU\n";
}
}
return 0;
}