Pagini recente » Cod sursa (job #1218363) | Cod sursa (job #1399502) | Cod sursa (job #2336805) | Cod sursa (job #2450577) | Cod sursa (job #1347383)
#include <fstream>
#define DIM 100003
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int Father[DIM];
int n, m;
inline void Read()
{
in >> n >> m;
for(int i = 1; i <= n; ++i)
Father[i] = i;
}
inline int Group(int x)
{
if( x != Father[x] )
Father[x] = Group(Father[x]);
return Father[x];
}
inline void Unite(int x, int y)
{
x = Group(x);
y = Group(y);
Father[x] = y;
}
inline void Solve()
{
int op, x, y;
for(int i = 1; i <= m; ++i)
{
in >> op >> x >> y;
if(op == 1)
Unite(x, y);
else
{
if( Group(x) == Group(y) )
out << "DA\n";
else
out << "NU\n";
}
}
}
int main()
{
Read();
Solve();
return 0;
}