vector<route_weight> MST_KRUSHAL(int N, min_priority_queue Q) { vector<route_weight> mst_routes; //Creating the disjoint set forest for each vertex. This stores information whether two nodes are connected by a path or not. map<int,int> connected; for (int i = 1; i <= N; ++i) { connected[i]=i; } while(!Q.empty()) { int u = Q.top().second.first, v = Q.top().second.second, w = Q.top().first; //parent_x stores information about the set that x belongs to. int parent_u = connected[u], parent_v = connected[v]; if(parent_u != parent_v) //if u and v are not connected by a path. { mst_routes.push_back(make_pair(w, make_pair(u, v))); for (int i = 1; i <= N; ++i) // UNION(u,v) { if(connected[i] == parent_v) { connected[i] = parent_u; } } } Q.pop(); } return mst_routes; }
std::vector<unsigned> extract10fromqueue(min_priority_queue &queue) { std::vector<unsigned> avector; for (int i = 0; i < 2; i++) { if (!queue.empty()) { avector.push_back((queue.top()).first); queue.pop(); } } return avector; }