Pagini recente » Cod sursa (job #936325) | Cod sursa (job #1262441) | Cod sursa (job #2183942) | Cod sursa (job #88580) | Cod sursa (job #1413676)
#include <fstream>
const int NMAX = 100005;
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int N,M;
int type,x,y;
int TT[NMAX];
void Update(int x, int y)
{
if (x > y)
swap(x,y);
TT[x] = y;
}
int Query(int x)
{
if (TT[x] == x)
return x;
TT[x] = Query(TT[x]);
return TT[x];
}
int main()
{
f >> N >> M;
for (int i = 1; i <= N; ++i)
{
TT[i] = i;
}
for (int i = 1; i <= M; ++i)
{
f >> type >> x >> y;
if (type == 1)
{
Update(x,y);
}
if (type == 2)
{
if (Query(x) == Query(y))
g << "DA\n";
else g << "NU\n";
}
}
f.close();
g.close();
return 0;
}