Pagini recente » Cod sursa (job #2467152) | Cod sursa (job #303365) | Cod sursa (job #1178711) | Cod sursa (job #115758) | Cod sursa (job #2576153)
#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;
int dx = getRoot(x);
int dy = getRoot(y);
if(c == 1)
T[dy] = dx;
else if(dx == dy)
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];
}