def shortest_path(digr, s):
 nodes_explored = set([s])
 nodes_unexplored = DFS(digr, s)
 nodes_unexplored.remove(s)
 dist = {s: 0}
 node_heap = []
 for n in nodes_unexplored:
  min = compute_min_dist(digr, n, nodes_explored, dist)
  heapq.heappush(node_heap, (min, n))
 while (len(node_heap) > 0):
  (min_dist, nearest_node) = heapq.heappop(node_heap)
  dist[nearest_node] = min_dist
  nodes_explored.add(nearest_node)
  nodes_unexplored.remove(nearest_node)
  for v in digr.neighbors(nearest_node):
   if (v in nodes_unexplored):
    for i in range(len(node_heap)):
     if (node_heap[i][1] == v):
      node_heap[i] = (compute_min_dist(digr, v, nodes_explored, dist), v)
      heapq.heapify(node_heap)
 return dist

def shortest_path ( digr , s ) : nodes_explored = set ( [ s ] ) nodes_unexplored = DFS ( digr , s ) nodes_unexplored . remove ( s ) dist = { s : 0 } node_heap = [ ] for n in nodes_unexplored : min = compute_min_dist ( digr , n , nodes_explored , dist ) heapq . heappush ( node_heap , ( min , n ) ) while ( len ( node_heap ) > 0 ) : ( min_dist , nearest_node ) = heapq . heappop ( node_heap ) dist [ nearest_node ] = min_dist nodes_explored . add ( nearest_node ) nodes_unexplored . remove ( nearest_node ) for v in digr . neighbors ( nearest_node ) : if ( v in nodes_unexplored ) : for i in range ( len ( node_heap ) ) : if ( node_heap [ i ] [ 1 ] == v ) : node_heap [ i ] = ( compute_min_dist ( digr , v , nodes_explored , dist ) , v ) heapq . heapify ( node_heap ) return dist
returns the shortest representation of the given locations .