51 absl::Span<const typename Graph::ArcIndex> sorted_arcs) {
53 const int num_arcs = graph.
num_arcs();
55 std::vector<ArcIndex> tree_arcs;
59 const int expected_tree_size = graph.
num_nodes() - 1;
60 tree_arcs.reserve(expected_tree_size);
63 while (tree_arcs.size() != expected_tree_size && arc_index < num_arcs) {
64 const ArcIndex arc = sorted_arcs[arc_index];
65 const auto tail = graph.
Tail(arc);
66 const auto head = graph.
Head(arc);
69 tree_arcs.push_back(arc);
114 const Graph& graph,
const ArcValue& arc_value) {
117 using ArcValueType =
decltype(arc_value(0));
118 std::vector<ArcIndex> tree_arcs;
122 const int expected_tree_size = graph.
num_nodes() - 1;
123 tree_arcs.reserve(expected_tree_size);
125 std::vector<bool> node_active(graph.
num_nodes(),
true);
132 void SetHeapIndex(
int index) { heap_index = index; }
133 int GetHeapIndex()
const {
return heap_index; }
134 bool operator<(
const Entry& other)
const {
return value > other.value; }
145 std::vector<Entry> entries;
146 std::vector<bool> touched_entry(graph.
num_nodes(),
false);
148 entries.push_back({.value = std::numeric_limits<ArcValueType>::max(),
152 entries[0].value = 0;
154 while (!pq.
IsEmpty() && tree_arcs.size() != expected_tree_size) {
155 const Entry* best = pq.
Top();
158 node_active[node] =
false;
160 tree_arcs.push_back(node_neighbor[node]);
164 if (node_active[neighbor]) {
165 const ArcValueType value = arc_value(arc);
166 Entry& entry = entries[neighbor];
167 if (value < entry.value || !touched_entry[neighbor]) {
168 node_neighbor[neighbor] = arc;
170 touched_entry[neighbor] =
true;