CompProgLibrary

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub RTnF/CompProgLibrary

:heavy_check_mark: cpp/graph/prim.hpp

Depends on

Verified with

Code

#pragma once
#include "graph/graph_list.hpp"
#include "template/small_template.hpp"

/**
 * プリム法
 * 無向グラフの最小全域森 O((E+V)logV)
 * 辺のコストが全て0以上
 * 返り値:コストの総和
 * https://algo-logic.info/prim-mst/
 */
template <class Cost, class E> Cost ListGraph<Cost, E>::prim() {
  Cost mst_dist = 0;
  using P = pair<Cost, int>;
  vector<Cost> dist(n_, ListGraph<Cost>::UNREACHABLE);
  vector<bool> used(n_, false);
  auto span = [&](int start_node) {
    dist[start_node] = 0;
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.emplace(0, start_node);
    while (!pq.empty()) {
      P p = pq.top();
      pq.pop();
      Cost v = p.second;
      if (used[v] || dist[v] < p.first) {
        continue;
      }
      mst_dist += dist[v];
      used[v] = true;
      for (const auto &e : adj[v]) {
        if (!used[e.to] && e.cost < dist[e.to]) {
          dist[e.to] = e.cost;
          pq.emplace(dist[e.to], e.to);
        }
      }
    }
  };
  for (int i = 0; i < n_; ++i) {
    if (!used[i]) {
      span(i);
    }
  }
  return mst_dist;
}
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/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.12.0/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus.py", line 187, in bundle
    bundler.update(path)
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/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.12.0/x64/lib/python3.12/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: graph/graph_list.hpp: line -1: no such header
Back to top page