Guest User

Untitled

a guest
Jun 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. KruskalMST(EdgeWeightedGraph G){
  2. priority_queue<Edge> pq;
  3. vector<Edge> e = G.edges(); // liefert alle Kanten von G
  4. for (int i = 0; i < e.size(); i++) pq.push(e[i]);
  5. for (int i = 0; i < G.V(); i++) marked[i] = i;
  6. while (!pq.isEmpty()) {
  7. Edge e = pq.top();
  8. pq.pop();
  9. int v = e.either(); int w = e.other(); // nodes connecting with the edge
  10. if (marked[v] != marked[w]) {
  11. mst.push(e);
  12. for (int i = 0; i<G.V(); i++){
  13. if (marked[i] == marked[w])
  14. marked[i] = marked[v];
  15. }
  16. }
  17. }
Add Comment
Please, Sign In to add comment