Java solutions using Dijkstra, Floyd–Warshall and Bellman-Ford algorithm
Floyd\u2013Warshall algorithm\nTime complexity: O(N^3), Space complexity: O(N^2)\n\npublic int networkDelayTime_FW(int[][] times, int N, int K) {\n    double[][
1. Floyd\u2013Warshall algorithm\nTime complexity: O(N^3), Space complexity: O(N^2)\n```\npublic int networkDelayTime_FW(int[][] times, int N, int K) {\n    double[][] disTo = new double[N][N];\n    for (int i = 0; i < N; i++) {\n        Arrays.fill(disTo[i], Double.POSITIVE_INFINITY);\n    }\n    for (int i = 0; i < N; i++) {\n        disTo[i][i] = 0;\n    }\n    for (int[] edge: times) {\n        disTo[edge[0] - 1][edge[1] - 1] = edge[2];\n    }\n    for (int k = 0; k < N; k++) {\n        for (int i = 0; i < N; i++) {\n            for (int j = 0; j < N; j++) {\n                if (disTo[i][j] > disTo[i][k] + disTo[k][j])\n                    disTo[i][j] = disTo[i][k] + disTo[k][j];\n            }\n        }\n    }\n    double max = Double.MIN_VALUE;\n    for (int i = 0; i < N; i++) {\n        if (disTo[K - 1][i] == Double.POSITIVE_INFINITY) return -1;\n        max = Math.max(max, disTo[K - 1][i]);\n    }\n    return (int) max;\n}\n```\n\n2. Bellman-Ford algorithm\nTime complexity: O(N*E), Space complexity: O(N)\n```\npublic int networkDelayTime_BF(int[][] times, int N, int K) {\n    double[] disTo = new double[N];\n    Arrays.fill(disTo, Double.POSITIVE_INFINITY);\n    disTo[K - 1] = 0;\n    for (int i = 1; i < N; i++) {\n        for (int[] edge : times) {\n            int u = edge[0] - 1, v = edge[1] - 1, w = edge[2];\n            disTo[v] = Math.min(disTo[v], disTo[u] + w);\n        }\n    }\n    double res = Double.MIN_VALUE;\n    for (double i: disTo) {\n        res = Math.max(i, res);\n    }\n    return res == Double.POSITIVE_INFINITY ? -1 : (int) res;\n}\n```\n\n3. Dijkstra\'s algorithm\nTime complexity: O(Nlog(N) + E), Space complexity: O(N + E)\n```\npublic int networkDelayTime_Dijkstra(int[][] times, int N, int K) {\n    Map<Integer, List<int[]>> graph = new HashMap<>();\n    for (int[] edge: times) {\n        graph.putIfAbsent(edge[0], new ArrayList<>());\n        graph.get(edge[0]).add(new int[]{edge[1], edge[2]});\n    }\n    PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> (a[0] - b[0]));\n    boolean[] visited = new boolean[N + 1];\n    int[] minDis = new int[N + 1];\n    Arrays.fill(minDis, Integer.MAX_VALUE);\n    minDis[K] = 0;\n    pq.offer(new int[]{0, K});\n    int max = 0;\n    while (!pq.isEmpty()) {\n        int[] curr = pq.poll();\n        int currNode = curr[1];\n        if (visited[currNode]) continue;\n        visited[currNode] = true;\n        int currDis = curr[0];\n        max = currDis;\n        N--;\n        if (!graph.containsKey(currNode)) continue;\n        for (int[] next : graph.get(currNode)) {\n            if (!visited[next[0]] && currDis + next[1] < minDis[next[0]])\n                pq.offer(new int[]{currDis + next[1], next[0]});\n        }\n    }\n    return N == 0 ? max : -1;\n}\n```\n
[]