Simple Python BFS solution
\n    def networkDelayTime(self, times: List[List[int]], N: int, K: int) -> int:\n        graph = [dict() for _ in range(N + 1)]\n        for u, v, w in times:\
```\n    def networkDelayTime(self, times: List[List[int]], N: int, K: int) -> int:\n        graph = [dict() for _ in range(N + 1)]\n        for u, v, w in times:\n            graph[u][v] = w\n        finished = [float(\'inf\') for _ in range(N + 1)]\n        # BFS visit\n        curr_level = {K}\n        finished[0], finished[K] = 0, 0\n        while curr_level:\n            next_level = set()\n            for u in curr_level:\n                for v in graph[u]:\n                    if finished[v] > finished[u] + graph[u][v]:\n                        finished[v] = finished[u] + graph[u][v]\n                        next_level.add(v)\n            curr_level = next_level\n        t = max(finished)\n        return t if t != float(\'inf\') else -1\n```
[]