def dijkstra_shortest_paths(graph, id, heuristic=None, directed=False):
 W = adjacency(graph, directed=directed, heuristic=heuristic)
 Q = []
 D = {}
 P = {}
 P[id] = [id]
 seen = {id: 0}
 heappush(Q, (0, id))
 while Q:
  (dist, v) = heappop(Q)
  if (v in D):
   continue
  D[v] = dist
  for w in W[v].keys():
   vw_dist = (D[v] + W[v][w])
   if ((w not in D) and ((w not in seen) or (vw_dist < seen[w]))):
    seen[w] = vw_dist
    heappush(Q, (vw_dist, w))
    P[w] = (P[v] + [w])
 for n in graph:
  if (n not in P):
   P[n] = None
 return P

def dijkstra_shortest_paths ( graph , id , heuristic = None , directed = False ) : W = adjacency ( graph , directed = directed , heuristic = heuristic ) Q = [ ] D = { } P = { } P [ id ] = [ id ] seen = { id : 0 } heappush ( Q , ( 0 , id ) ) while Q : ( dist , v ) = heappop ( Q ) if ( v in D ) : continue D [ v ] = dist for w in W [ v ] . keys ( ) : vw_dist = ( D [ v ] + W [ v ] [ w ] ) if ( ( w not in D ) and ( ( w not in seen ) or ( vw_dist < seen [ w ] ) ) ) : seen [ w ] = vw_dist heappush ( Q , ( vw_dist , w ) ) P [ w ] = ( P [ v ] + [ w ] ) for n in graph : if ( n not in P ) : P [ n ] = None return P
dijkstra algorithm for finding the shortest paths from the given node to all other nodes .