diff options
| author | mzuenni <michi.zuendorf@gmail.com> | 2022-06-27 17:19:28 +0200 |
|---|---|---|
| committer | mzuenni <michi.zuendorf@gmail.com> | 2022-06-27 17:19:28 +0200 |
| commit | 5ab8a5088b729a9953b8dff1b2a985dc8fb2098b (patch) | |
| tree | ed40d6936c0e9eee40ba62751cbf99ecddbaddc2 /graph/kruskal.cpp | |
| parent | adabbad9c51cf7cd3874bfde8eac1fbcf84fec10 (diff) | |
updated tcr
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; +}} |
