Pagini recente » Cod sursa (job #2218337) | Cod sursa (job #1763686) | Cod sursa (job #2913782) | Statistici Maxim Georgiana (georgianamaxim) | Cod sursa (job #2710342)
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, m, x, y, t;
int T[100005];
int get_root(int nod)
{
while(T[nod] > 0)
nod = T[nod];
return nod;
}
int main()
{
fin >> n >> m;
for(int i = 1; i <= n; i++)
T[i] = -1;
for(int i = 1; i <= m; i++)
{
fin >> t >> x >> y;
x = get_root(x);
y = get_root(y);
if(t == 1)
{
if(x == y)
continue;
if(T[x] < T[y])
{
T[x] += T[y];
T[y] = x;
}
else
{
T[y] += T[x];
T[x] = y;
}
}
else
{
if(x == y)
fout << "DA\n";
else
fout << "NU\n";
}
}
return 0;
}