Pagini recente » Cod sursa (job #1533156) | Cod sursa (job #1996470) | Cod sursa (job #1435037) | Cod sursa (job #503647) | Cod sursa (job #2576141)
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int n, m, T[N], getRoot(int);
int main()
{
f >> n >> m;
for(int i = 1; i <= n; i++)
T[i] = i;
for(; m; m--)
{
int c, x, y;
f >> c >> x >> y;
if(c == 1)
{
int dx = getRoot(x);
int dy = getRoot(y);
if(dx != dy)
T[y] = dx;
}
else
if(getRoot(x) == getRoot(y))
g << "DA\n";
else
g << "NU\n";
}
return 0;
}
int getRoot(int nod)
{
if(T[nod] == nod)
return nod;
T[nod] = getRoot(T[nod]);
return T[nod];
}