-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ11404.java
More file actions
47 lines (38 loc) · 1.42 KB
/
Copy pathJ11404.java
File metadata and controls
47 lines (38 loc) · 1.42 KB
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
41
42
43
44
45
46
47
package TIL;
import java.io.*;
public class J11404 {
static int[][] array;
public static void main(String[] args)throws IOException {
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
int city = Integer.parseInt(buffer.readLine());
int n = Integer.parseInt(buffer.readLine());
array = new int[city+1][city+1];
for(int i = 1; i<= city; i++) {
for (int j = 1; j <= city; j++) {
if(i == j) array[i][j] = 0;
else array[i][j] = 9999999;
}
}
for(int i = 1; i <= n; i++){
String input [] = buffer.readLine().split(" ");
int start = Integer.parseInt(input[0]);
int end = Integer.parseInt(input[1]);
int weight = Integer.parseInt(input[2]);
array[start][end] = Math.min(array[start][end], weight);
}
for(int k = 1; k<= city; k++){
for(int s = 1; s<= city; s++){
for(int e = 1; e<= city; e++){
array[s][e] = Math.min(array[s][e], array[s][k]+array[k][e]);
}
}
}
for(int i = 1; i<= city; i++) {
for (int j = 1; j <= city; j++) {
if (array[i][j] == 9999999) System.out.print("0" + " ");
else System.out.print(array[i][j]+ " ");
}
System.out.println();
}
}
}