Pagini recente » Cod sursa (job #993049) | Cod sursa (job #2427764) | Cod sursa (job #580858) | Cod sursa (job #855881) | Cod sursa (job #2173890)
#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 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)
{
if (fx > fy)
tata[fx] = fy;
else tata[fy] = fx;
}
else
{
if (fx == fy)
fout << "DA\n";
else fout << "NU\n";
}
}
return 0;
}