diff options
Diffstat (limited to 'graph/kruskal.cpp')
| -rw-r--r-- | graph/kruskal.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/graph/kruskal.cpp b/graph/kruskal.cpp new file mode 100644 index 0000000..af5a8ff --- /dev/null +++ b/graph/kruskal.cpp @@ -0,0 +1,9 @@ +sort(edges.begin(), edges.end()); +vector<edge> mst; +int 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; +}} |
