Pagini recente » Cod sursa (job #887795) | Cod sursa (job #3287239) | Cod sursa (job #2583708) | Cod sursa (job #2193405) | Cod sursa (job #1795027)
#include <iostream>
#include <fstream>
using namespace std;
const int nMax = 100005;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int n, m;
int father[nMax];
int GetFather(int x)
{
if(father[x] != x)
father[x] = GetFather(father[x]);
return father[x];
}
void citire()
{
in >> n >> m;
for(int i = 1; i <= n; ++i)
father[i] = i;
}
void rezolvare()
{
int x, y, t, fx, fy;
for(int i = 1; i <= m; ++i)
{
in >> t >> x >> y;
fx = GetFather(x);
fy = GetFather(y);
if(t == 1)
father[fx] = fy;
else
{
if(fx == fy) out << "DA\n";
else out << "NU\n";
}
}
}
int main()
{
citire();
rezolvare();
return 0;
}