Pagini recente » Cod sursa (job #2356845) | Cod sursa (job #1971046) | Cod sursa (job #1842664) | Cod sursa (job #2353949) | Cod sursa (job #2023867)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
#define lim 100010
int d[lim];
int get_dad(int x)
{
if(x != d[x]) d[x] = get_dad(d[x]);
return d[x];
}
int main()
{
int n, m, x, y, c, aux1, aux2;
fin >> n >> m;
for (int i=1; i <= n; i++)
d[i] = i;
for (int i=1; i <= m; i++)
{
fin >> c >> x >> y;
if (c == 1)
d[y] = get_dad(x);
else
{
aux1 = get_dad(x);
aux2 = get_dad(y);
if (aux1 == aux2) fout << "DA\n";
else fout << "NU\n";
}
}
fin.close();
fout.close();
return 0;
}