Pagini recente » Cod sursa (job #2089722) | Cod sursa (job #2947511) | Cod sursa (job #2597512) | Cod sursa (job #2347671) | Cod sursa (job #2173907)
#include <fstream>
#define nmax 100001
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int n, m, i, j, c, x, y, tata[nmax], fx, fy;
int f (int x)
{
if (tata[x] == x)
return x;
return tata[x] = f (tata[x]);
}
int main()
{
fin >> n >> m;
for (i = 1; i <= n; i++)
tata[i] = i;
for (i = 1; i <= m; i++)
{
fin >> c >> x >> y;
fx = f (x);
fy = f (y);
if (c == 1)
{
tata[fx] = fy;
}
else
{
if (fx == fy)
fout << "DA\n";
else fout << "NU\n";
}
}
fin.close ();
fout.close ();
return 0;
}