結果
問題 | No.1344 Typical Shortest Path Sum |
ユーザー | tenten |
提出日時 | 2023-01-12 09:28:27 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 123 ms / 2,000 ms |
コード長 | 2,515 bytes |
コンパイル時間 | 4,190 ms |
コンパイル使用メモリ | 92,580 KB |
実行使用メモリ | 39,600 KB |
最終ジャッジ日時 | 2024-12-23 02:49:46 |
合計ジャッジ時間 | 10,328 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
36,928 KB |
testcase_01 | AC | 52 ms
36,696 KB |
testcase_02 | AC | 51 ms
36,804 KB |
testcase_03 | AC | 54 ms
36,788 KB |
testcase_04 | AC | 52 ms
36,884 KB |
testcase_05 | AC | 50 ms
36,760 KB |
testcase_06 | AC | 53 ms
36,956 KB |
testcase_07 | AC | 51 ms
36,928 KB |
testcase_08 | AC | 51 ms
36,584 KB |
testcase_09 | AC | 53 ms
37,048 KB |
testcase_10 | AC | 52 ms
36,748 KB |
testcase_11 | AC | 50 ms
36,852 KB |
testcase_12 | AC | 53 ms
36,884 KB |
testcase_13 | AC | 53 ms
36,684 KB |
testcase_14 | AC | 51 ms
36,676 KB |
testcase_15 | AC | 50 ms
36,736 KB |
testcase_16 | AC | 59 ms
37,072 KB |
testcase_17 | AC | 50 ms
36,908 KB |
testcase_18 | AC | 52 ms
37,060 KB |
testcase_19 | AC | 50 ms
36,852 KB |
testcase_20 | AC | 52 ms
36,980 KB |
testcase_21 | AC | 50 ms
36,984 KB |
testcase_22 | AC | 51 ms
36,540 KB |
testcase_23 | AC | 52 ms
36,772 KB |
testcase_24 | AC | 50 ms
36,884 KB |
testcase_25 | AC | 51 ms
37,080 KB |
testcase_26 | AC | 53 ms
36,928 KB |
testcase_27 | AC | 49 ms
36,724 KB |
testcase_28 | AC | 52 ms
37,084 KB |
testcase_29 | AC | 52 ms
36,956 KB |
testcase_30 | AC | 52 ms
36,668 KB |
testcase_31 | AC | 50 ms
37,028 KB |
testcase_32 | AC | 51 ms
36,872 KB |
testcase_33 | AC | 51 ms
36,792 KB |
testcase_34 | AC | 49 ms
36,776 KB |
testcase_35 | AC | 50 ms
36,936 KB |
testcase_36 | AC | 50 ms
36,944 KB |
testcase_37 | AC | 49 ms
36,804 KB |
testcase_38 | AC | 49 ms
36,956 KB |
testcase_39 | AC | 49 ms
36,856 KB |
testcase_40 | AC | 76 ms
38,076 KB |
testcase_41 | AC | 79 ms
38,176 KB |
testcase_42 | AC | 77 ms
38,236 KB |
testcase_43 | AC | 78 ms
38,204 KB |
testcase_44 | AC | 79 ms
38,264 KB |
testcase_45 | AC | 77 ms
37,904 KB |
testcase_46 | AC | 81 ms
38,040 KB |
testcase_47 | AC | 80 ms
38,180 KB |
testcase_48 | AC | 79 ms
38,020 KB |
testcase_49 | AC | 77 ms
38,036 KB |
testcase_50 | AC | 79 ms
37,968 KB |
testcase_51 | AC | 80 ms
38,160 KB |
testcase_52 | AC | 75 ms
38,044 KB |
testcase_53 | AC | 78 ms
38,216 KB |
testcase_54 | AC | 77 ms
38,220 KB |
testcase_55 | AC | 78 ms
38,156 KB |
testcase_56 | AC | 78 ms
38,012 KB |
testcase_57 | AC | 78 ms
37,956 KB |
testcase_58 | AC | 77 ms
37,960 KB |
testcase_59 | AC | 78 ms
38,012 KB |
testcase_60 | AC | 55 ms
36,812 KB |
testcase_61 | AC | 51 ms
36,936 KB |
testcase_62 | AC | 116 ms
39,448 KB |
testcase_63 | AC | 58 ms
37,180 KB |
testcase_64 | AC | 79 ms
38,100 KB |
testcase_65 | AC | 123 ms
39,452 KB |
testcase_66 | AC | 118 ms
39,600 KB |
testcase_67 | AC | 120 ms
39,476 KB |
testcase_68 | AC | 57 ms
37,108 KB |
testcase_69 | AC | 59 ms
37,040 KB |
testcase_70 | AC | 52 ms
37,020 KB |
testcase_71 | AC | 49 ms
36,832 KB |
testcase_72 | AC | 49 ms
36,936 KB |
testcase_73 | AC | 51 ms
37,096 KB |
testcase_74 | AC | 50 ms
36,956 KB |
testcase_75 | AC | 49 ms
36,968 KB |
testcase_76 | AC | 50 ms
36,604 KB |
testcase_77 | AC | 50 ms
36,948 KB |
testcase_78 | AC | 54 ms
37,108 KB |
testcase_79 | AC | 54 ms
36,968 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static final long MAX = 1000000000000L * 100; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); long[][] costs = new long[n][n]; for (int i = 0; i < n; i++) { Arrays.fill(costs[i], Long.MAX_VALUE / 2); costs[i][i] = 0; } for (int i = 0; i < m; i++) { int s = sc.nextInt() - 1; int t = sc.nextInt() - 1; long c = sc.nextLong(); costs[s][t] = Math.min(costs[s][t], c); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { costs[j][k] = Math.min(costs[j][k], costs[j][i] + costs[i][k]); } } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { long sum = 0; for (int j = 0; j < n; j++) { if (costs[i][j] < MAX) { sum += costs[i][j]; } } sb.append(sum).append("\n"); } System.out.print(sb); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }