Inside dijkstra.py
heap = [(0, source)]
while heap:
distance, node = heapq.heappop(heap)
if distance > dist[node]:
continue # stale entry
for neighbor, weight in graph[node]:
new_distance = distance + weight
if new_distance < dist[neighbor]:
dist[neighbor] = new_distance
prev[neighbor] = node
heapq.heappush(heap, (new_distance, neighbor))
Our team's Python implementation, running in your browser as a line-for-line JavaScript port. Binary heap with lazy deletion, O((V + E) log V). It returns the same path as the Python on 400 of 400 test routes.