Pagini recente » Cod sursa (job #2733769) | ichb-scoala-2014-9 | Cod sursa (job #2551514) | Cod sursa (job #2059405) | Cod sursa (job #1231738)
#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];
int root(int l)
{
if (P[l] == l)
return l;
return root(P[l]);
}
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[root(b)] = root(a);
}
else
{
if (root(a) == root(b))
fout << "DA\n";
else
fout << "NU\n";
}
}
}
int main()
{
citire();
fin.close();
fout.close();
return 0;
}