Pagini recente » Cod sursa (job #2707440) | Cod sursa (job #1515702) | Cod sursa (job #1744109) | Cod sursa (job #2463326) | Cod sursa (job #1231724)
#include <iostream>
#include <fstream>
#define nmax 100005
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, m;
int t, a, b;
int i, p1, p2;
int P[nmax], NR[nmax];
int root(int x)
{
if (P[x] == x)
return x;
return root(P[x]);
}
void init()
{
for (i=1; i<=n; i++)
P[i] = i;
}
void citire()
{
fin >> n >> m;
init();
for (i=1; i<=m; i++)
{
fin >> t >> a >> b;
if (t == 1)
{
P[a] = b;
}
else
{
p1 = root(a);
p2 = root(b);
if (p1 == p2)
fout << "DA\n";
else
fout << "NU\n";
}
}
}
int main()
{
citire();
fin.close();
fout.close();
return 0;
}