summaryrefslogtreecommitdiff
path: root/graph/kruskal.cpp
blob: 0bd2e2209658dddc8cacf66c01373f74b705c66f (plain)
1
2
3
4
5
6
7
8
9
// Union-Find Implementierung von oben. Laufzeit: O(|E|*log(|E|))
sort(edges.begin(), edges.end());
vector<ii> mst; int cost = 0;
for (auto &e : edges) {
  if (findSet(e.from) != findSet(e.to)) {
    unionSets(e.from, e.to);
    mst.push_back(ii(e.from, e.to));
    cost += e.cost;
}}