Pagini recente » Cod sursa (job #3191782) | Cod sursa (job #2643453) | Cod sursa (job #2413179) | Cod sursa (job #2955094) | Cod sursa (job #1921972)
#include <fstream>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int N, V[100001];
int stramos(int x){
if(V[x] == x)
return x;
V[x] = stramos(V[x]);
return V[x];
}
int main()
{
int m, i, v, x, y, nx, ny;
f >> N >> m;
for(i = 1; i <= N; i++)
V[i] = i;
for(i = 1; i <= m; i++){
f >> v >> x >> y;
if(v == 1){
nx = stramos(x);
ny = stramos(y);
V[nx] = V[ny];
}
else{
if(stramos(x) == stramos(y))
g << "DA";
else
g << "NU";
g << '\n';
}
}
return 0;
}