def graph_distances(start, edges, distances):
<EOL>adj = {x: [] for x in range(len(distances))}<EOL>for n1, n2 in edges:<EOL><INDENT>adj[n1].append(n2)<EOL>adj[n2].append(n1)<EOL><DEDENT>to_visit = []<EOL>new_dist = {}<EOL>for n in adj[start]:<EOL><INDENT>heapq.heappush(to_visit, (distances[start, n], n))<EOL><DEDENT>while to_visit:<EOL><INDENT>d, next_node = heapq.heappop(to_visit)<EOL>if next_node not in new_dist:<EOL><INDENT>new_dist[next_node] = d<EOL><DEDENT>for n in adj[next_node]:<EOL><INDENT>if n not in new_dist:<EOL><INDENT>heapq.heappush(to_visit, (d + distances[next_node, n], n))<EOL><DEDENT><DEDENT><DEDENT>return new_dist<EOL>
Given an undirected adjacency list and a pairwise distance matrix between
all nodes: calculates distances along graph from start node.

Args:
    start (int): start node
    edges (list): adjacency list of tuples
    distances (array): 2d array of distances between nodes

Returns:
    dict of node to distance from start