Java BFS Solution
\nclass Solution {\n    public int networkDelayTime(int[][] times, int N, int K) {\n        Map<Integer, Map<Integer, Integer>> map = new HashMap<>();\n        
```\nclass Solution {\n    public int networkDelayTime(int[][] times, int N, int K) {\n        Map<Integer, Map<Integer, Integer>> map = new HashMap<>();\n        for (int[] t : times) {\n            int from = t[0];\n            int to = t[1];\n            int weight = t[2];\n            map.putIfAbsent(from, new HashMap<>());\n            map.get(from).put(to, weight);\n        }\n        int[] res = new int[N + 1];\n        Arrays.fill(res, Integer.MAX_VALUE);\n        res[K] = 0;\n        Queue<int[]> queue = new ArrayDeque<>();\n        queue.offer(new int[]{K, 0});\n        while (!queue.isEmpty()) {\n            int[] cur = queue.poll();\n            int node = cur[0];\n            int weight = cur[1];\n            for (int next : map.getOrDefault(node, new HashMap<>()).keySet()) {\n                int w = map.get(node).get(next);\n                if (w + weight < res[next]) {\n                    res[next] = w + weight;\n                    queue.offer(new int[]{next, w + weight});\n                }\n            }\n        }\n        int max = 0;\n        for (int i = 1; i <= N; ++i) {\n            if (res[i] == Integer.MAX_VALUE) {\n                return -1;\n            }\n            max = Math.max(max, res[i]);\n        }\n        return max;\n    }\n}\n```
['Java']