Pagini recente » Cod sursa (job #1211813) | Cod sursa (job #2296505) | Cod sursa (job #290551) | Cod sursa (job #1614015) | Cod sursa (job #1921893)
#include <fstream>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int N, V[100001];
//int NRV[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;
//NRV[i] = 1;
}
for(i = 1; i <= m; i++){
f >> v >> x >> y;
if(v == 1){
nx = stramos(x);
ny = stramos(y);
//if(NRV[nx] > NRV[ny]){
V[nx] = V[ny];
// NRV[ny] += NRV[nx];
// }
//else{
//V[ny] = V[nx];
// NRV[nx] += NRV[ny];
// }
}
else{
if(stramos(x) == stramos(y))
g << "DA";
else
g << "NU";
g << '\n';
}
}
return 0;
}