summaryrefslogtreecommitdiff
path: root/graph/kruskal.cpp
blob: 5b0e153f64986841d4df5d89c2f4e627e99da202 (plain)
1
2
3
4
5
6
7
8
9
sort(all(edges));
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;
}}