This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
import heapq | |
def shortestPath(edges, source, sink): | |
# create a weighted DAG - {node:[(cost,neighbour), ...]} | |
graph = collections.defaultdict(list) | |
for l, r, c in edges: | |
graph[l].append((c,r)) | |
# create a priority queue and hash set to store visited nodes | |
queue, visited = [(0, source, [])], set() |