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