Java || best question to understand Dijkastras
\nclass Solution {\n    public int networkDelayTime(int[][] times, int n, int K) {\n        int[][] graph = new int[n][n];\n        for(int i = 0; i < n ; i++) 
```\nclass Solution {\n    public int networkDelayTime(int[][] times, int n, int K) {\n        int[][] graph = new int[n][n];\n        for(int i = 0; i < n ; i++) Arrays.fill(graph[i], Integer.MAX_VALUE);\n        for( int[] rows : times) graph[rows[0] - 1][rows[1] - 1] =  rows[2];        \n        \n        int[] distance = new int[n];\n        Arrays.fill(distance, Integer.MAX_VALUE);\n        distance[K - 1] = 0;\n        \n        boolean[] visited = new boolean[n];\n        for(int i = 0; i < n ; i++){\n            int v = minIndex(distance, visited);\n            if(v == -1)continue;\n            visited[v] = true;\n            for(int j = 0; j < n; j++){\n                if(graph[v][j] != Integer.MAX_VALUE){\n                    int newDist = graph[v][j] + distance[v];\n                    if(newDist < distance[j]) distance[j] = newDist;\n                }\n            }\n        }\n        int result = 0;\n        for(int dist : distance){\n            if(dist == Integer.MAX_VALUE) return -1;\n            result = Math.max(result, dist);\n        }\n        return result;\n    }\n\t\n    private int minIndex(int[] distance, boolean[] visited){\n        int min = Integer.MAX_VALUE, minIndex = -1;\n        for(int i = 0; i < distance.length; i++){\n            if(!visited[i] && distance[i] < min){\n                min = distance[i];\n                minIndex = i;\n            }\n        }\n        return minIndex;\n    }\n}\n```
['Java']