✅ [Python] propagation through all paths using Dijkstra's Algorithm (with detailed comments)
\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.\n*\nThis solution employs Dijkstra\'s algorithm to propagate signal through the network. \n\n*Comment. To get m
**\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.**\n****\nThis solution employs Dijkstra\'s algorithm to propagate signal through the network. \n\n**Comment**. To get minimal signal arrival time for each node, we propagate through all paths using double-ended queue. On each iteration, we send signal from a source node to all its destination nodes (according to the network\'s graph) and update time. We also note that there is no point to propagate further if the signal has already reached some node via another path with better time.\n\n```\nclass Solution:\n    def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int:\n        \n        # [1] convert edge data to a hashmap\n        graph = defaultdict(list)\n        for u, v, w in times: graph[u].append((v, w))\n            \n        # [2] signal minimal time to reach each node\n        MAX_TIME = 6000*100+1\n        signal = [MAX_TIME] * (n+1)\n        signal[k] = 0\n        \n        # [3] propagate signal through all possible\n        #     paths iteratively using deque\n        dq = deque([k])\n        while dq:\n            node_from = dq.popleft()\n            time_from = signal[node_from]\n            for node_to, time_to in graph[node_from]:\n                # [4] there is no point to propagate further if the signal has\n                #     already reached this node via another path with better time\n                time = time_from + time_to\n                if time < signal[node_to]:\n                    signal[node_to] = time\n                    dq.append(node_to)\n\n        # [5] check time for all nodes\n        if all(map(lambda t: t < MAX_TIME, signal[1:n+1])):\n            return max(signal[1:n+1])\n        else:        \n            return -1\n```
[]