You are viewing a single comment's thread. Return to all comments →
I used a similar approach, with a few minor differences*. Note that unvisited is redundant, as you can just check distances < 0.
unvisited
distances < 0
(*e.g. collections.deque for a Queue, and initial distances [0] + n * [float('inf')] to allow 1-based indexing)
collections.deque
[0] + n * [float('inf')]
BFS: Shortest Reach in a Graph
You are viewing a single comment's thread. Return to all comments →
I used a similar approach, with a few minor differences*. Note that
unvisited
is redundant, as you can just checkdistances < 0
.(*e.g.
collections.deque
for a Queue, and initial distances[0] + n * [float('inf')]
to allow 1-based indexing)