diff options
Diffstat (limited to 'content/graph/kruskal.cpp')
| -rw-r--r-- | content/graph/kruskal.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/content/graph/kruskal.cpp b/content/graph/kruskal.cpp new file mode 100644 index 0000000..987d30b --- /dev/null +++ b/content/graph/kruskal.cpp @@ -0,0 +1,9 @@ +sort(all(edges)); +vector<Edge> mst; +ll cost = 0; +for (Edge& e : edges) { + if (findSet(e.from) != findSet(e.to)) { + unionSets(e.from, e.to); + mst.push_back(e); + cost += e.cost; +}} |
