Python Solution - Dijkstra's Shortest Path Algorithm using minHeap
\n# Implement Dijkstra\'s Shortest Path Algorithm\n\nclass Solution:\n    def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int:\n        # 
```\n# Implement Dijkstra\'s Shortest Path Algorithm\n\nclass Solution:\n    def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int:\n        # create Adjacency List \n        adjList = {i:[] for i in range(1, n+1)}\n        for u, v, w in times:\n            adjList[u].append((v, w))\n        \n        minHeap = [(0, k)]  # taking min-heap so that pop() will give node with lowest distance\n        t = 0   # total time require\n        visited = set()  # to keep a track of visited nodes\n        \n        while minHeap:\n            w1, n1 = heapq.heappop(minHeap)  # w1 = time to reach from source k(weight); n1 = value of node\n            if n1 in visited: continue\n            visited.add(n1)\n            t = max(t, w1)  # as w1 is the total time to reach to n1 from k\n            for n2, w2 in adjList[n1]:\n                if n2 not in visited:\n                    heapq.heappush(minHeap, (w1 + w2, n2)) # added current time(w1) + time between n1 and n2\n        \n        # if we can visit all nodes then only return total time t\n        return t if len(visited) == n else -1 \n\n# number of edges, e = len(times)\n# n = total no. of nodes\n\n# Time: O(e * log(n)) \n# Space: O(n)\n```
['Heap (Priority Queue)', 'Python', 'Python3']