JAVA Djikstra's Solution
Someone would use Queue instead of PriorityQueue.\n\n    public int networkDelayTime(int[][] times, int N, int K) {\n        if (times == null || times.length =
Someone would use Queue instead of PriorityQueue.\n```\n    public int networkDelayTime(int[][] times, int N, int K) {\n        if (times == null || times.length == 0 || times[0].length == 0) {\n        return -1;\n        }\n        int[][] grid = new int[N + 1][N + 1];\n        for (int[] arr : grid) {\n            Arrays.fill(arr, Integer.MAX_VALUE);\n        }\n        for (int[] curEdge : times) {\n            grid[curEdge[0]][curEdge[1]] = curEdge[2];\n        }\n\n        int[] res = new int[N + 1];\n        Arrays.fill(res, Integer.MAX_VALUE);\n        PriorityQueue<Integer> minHeap = new PriorityQueue<Integer>(N, new Comparator<Integer>() {\n          @Override\n          public int compare(Integer c1, Integer c2) {\n            return res[c1] - res[c2];\n          }\n        });\n        minHeap.offer(K);\n        res[K] = 0;\n        while (!minHeap.isEmpty()) {\n          Integer start = minHeap.poll();\n          for (int i = 1; i <= N; i++) {\n            int curWeight = grid[start][i];\n            if (curWeight != Integer.MAX_VALUE && res[i] > res[start] + curWeight) {\n              res[i] = res[start] + curWeight;\n              minHeap.offer(i);\n            }\n          }\n        }\n        int count = 0;\n        for (int i = 1; i <= N; i++) {\n          if (res[i] == Integer.MAX_VALUE) {\n            return -1;\n          }\n          count = Math.max(count, res[i]);\n        }\n        return count;\n    }\n```
[]