結果
問題 | No.1344 Typical Shortest Path Sum |
ユーザー | tenten |
提出日時 | 2023-01-12 09:28:27 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 119 ms / 2,000 ms |
コード長 | 2,515 bytes |
コンパイル時間 | 2,581 ms |
コンパイル使用メモリ | 92,260 KB |
実行使用メモリ | 40,100 KB |
最終ジャッジ日時 | 2024-06-02 07:58:39 |
合計ジャッジ時間 | 9,112 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
37,328 KB |
testcase_01 | AC | 48 ms
37,324 KB |
testcase_02 | AC | 49 ms
37,356 KB |
testcase_03 | AC | 49 ms
37,264 KB |
testcase_04 | AC | 52 ms
36,992 KB |
testcase_05 | AC | 49 ms
37,044 KB |
testcase_06 | AC | 48 ms
36,796 KB |
testcase_07 | AC | 47 ms
37,292 KB |
testcase_08 | AC | 49 ms
37,268 KB |
testcase_09 | AC | 48 ms
37,300 KB |
testcase_10 | AC | 49 ms
37,280 KB |
testcase_11 | AC | 49 ms
37,228 KB |
testcase_12 | AC | 51 ms
36,880 KB |
testcase_13 | AC | 48 ms
37,228 KB |
testcase_14 | AC | 48 ms
37,336 KB |
testcase_15 | AC | 48 ms
37,144 KB |
testcase_16 | AC | 57 ms
37,316 KB |
testcase_17 | AC | 48 ms
37,328 KB |
testcase_18 | AC | 53 ms
37,356 KB |
testcase_19 | AC | 51 ms
37,280 KB |
testcase_20 | AC | 48 ms
37,260 KB |
testcase_21 | AC | 47 ms
37,136 KB |
testcase_22 | AC | 47 ms
37,224 KB |
testcase_23 | AC | 49 ms
36,972 KB |
testcase_24 | AC | 48 ms
37,124 KB |
testcase_25 | AC | 49 ms
37,268 KB |
testcase_26 | AC | 48 ms
37,272 KB |
testcase_27 | AC | 51 ms
37,192 KB |
testcase_28 | AC | 50 ms
37,292 KB |
testcase_29 | AC | 49 ms
37,136 KB |
testcase_30 | AC | 49 ms
37,132 KB |
testcase_31 | AC | 50 ms
37,352 KB |
testcase_32 | AC | 48 ms
37,288 KB |
testcase_33 | AC | 49 ms
37,060 KB |
testcase_34 | AC | 49 ms
37,440 KB |
testcase_35 | AC | 49 ms
37,052 KB |
testcase_36 | AC | 49 ms
37,308 KB |
testcase_37 | AC | 49 ms
37,340 KB |
testcase_38 | AC | 48 ms
37,192 KB |
testcase_39 | AC | 52 ms
37,280 KB |
testcase_40 | AC | 72 ms
38,012 KB |
testcase_41 | AC | 77 ms
38,468 KB |
testcase_42 | AC | 80 ms
38,460 KB |
testcase_43 | AC | 75 ms
38,080 KB |
testcase_44 | AC | 71 ms
38,384 KB |
testcase_45 | AC | 72 ms
38,328 KB |
testcase_46 | AC | 77 ms
38,244 KB |
testcase_47 | AC | 76 ms
38,284 KB |
testcase_48 | AC | 73 ms
38,172 KB |
testcase_49 | AC | 73 ms
38,416 KB |
testcase_50 | AC | 74 ms
38,508 KB |
testcase_51 | AC | 78 ms
38,564 KB |
testcase_52 | AC | 75 ms
38,040 KB |
testcase_53 | AC | 76 ms
38,412 KB |
testcase_54 | AC | 76 ms
38,504 KB |
testcase_55 | AC | 71 ms
38,372 KB |
testcase_56 | AC | 73 ms
38,392 KB |
testcase_57 | AC | 73 ms
38,192 KB |
testcase_58 | AC | 77 ms
38,348 KB |
testcase_59 | AC | 76 ms
38,040 KB |
testcase_60 | AC | 52 ms
37,372 KB |
testcase_61 | AC | 48 ms
37,320 KB |
testcase_62 | AC | 114 ms
39,940 KB |
testcase_63 | AC | 61 ms
38,124 KB |
testcase_64 | AC | 76 ms
37,956 KB |
testcase_65 | AC | 119 ms
40,096 KB |
testcase_66 | AC | 108 ms
40,100 KB |
testcase_67 | AC | 105 ms
39,664 KB |
testcase_68 | AC | 56 ms
37,696 KB |
testcase_69 | AC | 65 ms
37,688 KB |
testcase_70 | AC | 49 ms
37,436 KB |
testcase_71 | AC | 47 ms
37,344 KB |
testcase_72 | AC | 49 ms
37,304 KB |
testcase_73 | AC | 49 ms
37,016 KB |
testcase_74 | AC | 51 ms
36,632 KB |
testcase_75 | AC | 51 ms
37,352 KB |
testcase_76 | AC | 51 ms
36,676 KB |
testcase_77 | AC | 50 ms
37,288 KB |
testcase_78 | AC | 48 ms
37,016 KB |
testcase_79 | AC | 52 ms
37,036 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(); } }