115 const Graph&
graph,
const ArcValue& arc_value) {
118 using ArcValueType =
decltype(arc_value(0));
119 std::vector<ArcIndex> tree_arcs;
120 if (
graph.num_nodes() == 0) {
123 const int expected_tree_size =
graph.num_nodes() - 1;
124 tree_arcs.reserve(expected_tree_size);
126 std::vector<bool> node_active(
graph.num_nodes(),
true);
133 void SetHeapIndex(
int index) { heap_index =
index; }
134 int GetHeapIndex()
const {
return heap_index; }
135 bool operator<(
const Entry& other)
const {
return value > other.value; }
143 std::vector<Entry> entries;
144 std::vector<bool> touched_entry(
graph.num_nodes(),
false);
146 entries.push_back({node, std::numeric_limits<ArcValueType>::max(), -1});
148 entries[0].value = 0;
150 while (!pq.
IsEmpty() && tree_arcs.size() != expected_tree_size) {
151 const Entry* best = pq.
Top();
154 node_active[node] =
false;
156 tree_arcs.push_back(node_neighbor[node]);
160 if (node_active[neighbor]) {
161 const ArcValueType
value = arc_value(
arc);
162 Entry& entry = entries[neighbor];
163 if (
value < entry.value || !touched_entry[neighbor]) {
164 node_neighbor[neighbor] =
arc;
166 touched_entry[neighbor] =
true;