1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| class Main{ public static void main(String[] args){ int inf = 1000000000; int[][] dist = new int[n+1][n+1]; for(int i = 0; i < n; i++){ for(int j = 0; j < n; i++){ if(i==j){ dist[i][j] = 0; }else{ dist[i][j] = inf; } } } int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); dist[a][b] = Math.min(dist[a][b], c) floyd(dist, n); }
public static void floyd(int[][] dist, int n){ for(int k = 0; k < n; k++){ for(int i = 0 ; i < n; i++){ for(int j = 0; j < n; j++){ dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]); } } } } }
|