This documentation is automatically generated by online-judge-tools/verification-helper
#include "graph/minimum-spanning-tree.hpp"#pragma once
#include "../data-structure/union-find.hpp"
#include "./base.hpp"
#include "./graph-type.hpp"
#include <queue>
namespace matumoto {
template <typename Cost>
struct MinimumSpanningTree {
vector<pair<Cost, int>> graph_;
vector<pair<Cost, int>> mst_;
MinimumSpanningTree(const vector<pair<Cost, int>> &graph): graph_(graph) {}
Cost kruskal() {
mst_ = vector<pair<Cost, int>>(graph_.size()); // init
if (graph_.size() == 0) {
return Cost(0);
}
vector<WeightedEdge<Cost>> edges = graph_.edges();
sort(edges.begin(), edges.end());
matumoto::UnionFind uf(graph_.size());
Cost sum = 0;
for (auto edge: edges) {
int from = edge.from();
int to = edge.to();
if (uf.same(from, to))
continue;
uf.merge(from, to);
sum += edge.cost();
mst_.add_edge(edge);
}
return sum;
}
Cost prim() {
mst_ = vector<pair<Cost, int>>(graph_.size()); // init
if (graph_.size() == 0) {
return Cost(0);
}
priority_queue<WeightedEdge<Cost>, vector<WeightedEdge<Cost>>, greater<WeightedEdge<Cost>>> pq;
pq.emplace(/*from=*/0, /*to=*/0, Cost(0));
vector<vector<WeightedEdge<Cost>>> adj_list = graph_.graph();
vector<bool> used(graph_.size(), false);
Cost sum = 0;
while (not pq.empty()) {
auto e = pq.top();
pq.pop();
int v = e.to();
if (used[v])
continue;
sum += e.cost();
used[v] = true;
mst_.add_edge(e);
for (auto edge: adj_list[v]) {
int to = edge.to();
if (used[to])
continue;
pq.push(edge);
}
}
return sum;
}
};
} // namespace matumotoTraceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/onlinejudge_verify/languages/cplusplus.py", line 187, in bundle
bundler.update(path)
File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/onlinejudge_verify/languages/cplusplus_bundle.py", line 401, in update
self.update(self._resolve(pathlib.Path(included), included_from=path))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/onlinejudge_verify/languages/cplusplus_bundle.py", line 260, in _resolve
raise BundleErrorAt(path, -1, "no such header")
onlinejudge_verify.languages.cplusplus_bundle.BundleErrorAt: ../data-structure/union-find.hpp: line -1: no such header