Java Simple Djikstra
1, based on Djikstra\n2, check shortes dist from origin for each node. Once found the shortest, put it in vs to avoid duplicate. before put in set, compare to r
1, based on Djikstra\n2, check shortes dist from origin for each node. Once found the shortest, put it in vs to avoid duplicate. before put in set, compare to res, and record the longest node to reach\n3, nit: check if all nodes could be reachable.\n\n```\n    public int networkDelayTime(int[][] times, int N, int K) {\n        Map<Integer, Map<Integer, Integer>> g = new HashMap<>();\n        for (int[] time : times) {\n            g.computeIfAbsent(time[0], k -> new HashMap<>());\n            g.get(time[0]).put(time[1], time[2]);\n        }\n        PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> a[1] - b[1]);\n        Set<Integer> vs = new HashSet<>();\n        pq.offer(new int[]{K, 0});\n        int res = 0;\n        while (!pq.isEmpty()) {\n            int[] curr = pq.poll();            \n            if (vs.contains(curr[0])) continue;\n            vs.add(curr[0]);\n            res = Math.max(res, curr[1]);  // this must be after vs check, say[[1,2,1],[2,1,3]] 2, 2\n            for (int neig : g.getOrDefault(curr[0], new HashMap<Integer,Integer>()).keySet()) {\n                if (vs.contains(neig)) continue;\n                pq.offer(new int[]{neig, g.get(curr[0]).get(neig) + curr[1]});\n            }\n        }\n        return vs.size() == N ? res : -1;  // check if all nods visited; say [[1,2,1]], 2, 2\n    }\n```
[]