MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / mst

Function mst

code/graph/kruskals_mst.cpp:2–13  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include "../data-structures/union_find.cpp"
2vector<pair<int, ii> > mst(int n,
3 vector<pair<int, ii> > edges) {
4 union_find uf(n);
5 sort(edges.begin(), edges.end());
6 vector<pair<int, ii> > res;
7 rep(i,0,size(edges))
8 if (uf.find(edges[i].second.first) !=
9 uf.find(edges[i].second.second)) {
10 res.push_back(edges[i]);
11 uf.unite(edges[i].second.first,
12 edges[i].second.second); }
13 return res; }
14// vim: cc=60 ts=2 sts=2 sw=2:

Callers 1

testFunction · 0.85

Calls 3

push_backMethod · 0.80
uniteMethod · 0.80
findMethod · 0.45

Tested by 1

testFunction · 0.68