Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. // roads is edge-list. mst is reduced edge-list
  2.  
  3. sort(roads.begin(), roads.end(), [](Road *r1, Road *r2) {
  4. return r1->cost < r2->cost;
  5. });
  6.  
  7. vector<Road*> mst;
  8. for (auto road : roads) { // fills in MST (or forest)
  9. if (! (road->c1->built && road->c1->built)) {
  10. road->c1->reachable = true;
  11. road->c2->reachable = true;
  12. mst.push_back(road);
  13. }
  14. cout << road->c1->id << " " << road->c2->id << " " << road->cost << endl;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement