結果

問題 No.1344 Typical Shortest Path Sum
ユーザー tentententen
提出日時 2021-01-18 12:46:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 1,032 bytes
コンパイル時間 2,692 ms
コンパイル使用メモリ 77,092 KB
実行使用メモリ 45,652 KB
最終ジャッジ日時 2024-05-08 02:30:55
合計ジャッジ時間 15,583 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
41,180 KB
testcase_01 AC 116 ms
41,272 KB
testcase_02 AC 107 ms
40,152 KB
testcase_03 AC 128 ms
41,640 KB
testcase_04 AC 111 ms
40,100 KB
testcase_05 AC 114 ms
41,096 KB
testcase_06 AC 105 ms
40,256 KB
testcase_07 AC 116 ms
41,192 KB
testcase_08 AC 104 ms
39,916 KB
testcase_09 AC 124 ms
41,436 KB
testcase_10 AC 112 ms
41,024 KB
testcase_11 AC 116 ms
41,084 KB
testcase_12 AC 119 ms
41,160 KB
testcase_13 AC 111 ms
40,876 KB
testcase_14 AC 123 ms
41,344 KB
testcase_15 AC 106 ms
40,044 KB
testcase_16 AC 136 ms
41,376 KB
testcase_17 AC 117 ms
41,352 KB
testcase_18 AC 111 ms
41,064 KB
testcase_19 AC 119 ms
41,144 KB
testcase_20 AC 105 ms
39,960 KB
testcase_21 AC 115 ms
41,196 KB
testcase_22 AC 104 ms
40,208 KB
testcase_23 AC 120 ms
41,672 KB
testcase_24 AC 117 ms
41,120 KB
testcase_25 AC 108 ms
40,268 KB
testcase_26 AC 117 ms
41,572 KB
testcase_27 AC 115 ms
41,224 KB
testcase_28 AC 119 ms
41,192 KB
testcase_29 AC 103 ms
39,848 KB
testcase_30 AC 129 ms
41,556 KB
testcase_31 AC 119 ms
41,416 KB
testcase_32 AC 115 ms
41,248 KB
testcase_33 AC 110 ms
41,148 KB
testcase_34 AC 116 ms
41,136 KB
testcase_35 AC 118 ms
41,364 KB
testcase_36 AC 112 ms
40,928 KB
testcase_37 AC 107 ms
40,444 KB
testcase_38 AC 115 ms
41,396 KB
testcase_39 AC 118 ms
41,396 KB
testcase_40 AC 156 ms
41,836 KB
testcase_41 AC 156 ms
41,740 KB
testcase_42 AC 148 ms
41,652 KB
testcase_43 AC 139 ms
40,956 KB
testcase_44 AC 152 ms
41,720 KB
testcase_45 AC 150 ms
41,536 KB
testcase_46 AC 147 ms
41,776 KB
testcase_47 AC 156 ms
41,960 KB
testcase_48 AC 162 ms
41,836 KB
testcase_49 AC 154 ms
41,144 KB
testcase_50 AC 153 ms
41,912 KB
testcase_51 AC 149 ms
41,564 KB
testcase_52 AC 143 ms
41,564 KB
testcase_53 AC 162 ms
42,000 KB
testcase_54 AC 147 ms
41,612 KB
testcase_55 AC 152 ms
41,636 KB
testcase_56 AC 155 ms
42,040 KB
testcase_57 AC 151 ms
41,892 KB
testcase_58 AC 154 ms
41,712 KB
testcase_59 AC 156 ms
41,620 KB
testcase_60 AC 158 ms
42,124 KB
testcase_61 AC 124 ms
40,980 KB
testcase_62 AC 203 ms
45,568 KB
testcase_63 AC 174 ms
42,764 KB
testcase_64 AC 179 ms
43,420 KB
testcase_65 AC 218 ms
45,508 KB
testcase_66 AC 195 ms
45,484 KB
testcase_67 AC 209 ms
45,652 KB
testcase_68 AC 159 ms
42,376 KB
testcase_69 AC 164 ms
42,452 KB
testcase_70 AC 122 ms
41,360 KB
testcase_71 AC 120 ms
41,336 KB
testcase_72 AC 103 ms
40,224 KB
testcase_73 AC 103 ms
40,552 KB
testcase_74 AC 116 ms
41,224 KB
testcase_75 AC 118 ms
41,116 KB
testcase_76 AC 113 ms
41,192 KB
testcase_77 AC 108 ms
41,192 KB
testcase_78 AC 105 ms
40,304 KB
testcase_79 AC 134 ms
41,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		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 / 10);
		    costs[i][i] = 0;
		}
		for (int i = 0; i < m; i++) {
		    int left = sc.nextInt() - 1;
		    int right = sc.nextInt() - 1;
		    long value = sc.nextLong();
		    costs[left][right] = Math.min(costs[left][right], value);
		}
		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 ans = 0;
		    for (int j = 0; j < n; j++) {
		        if (costs[i][j] < Long.MAX_VALUE / 20) {
		            ans += costs[i][j];
		        }
		    }
		    sb.append(ans).append("\n");
		}
		System.out.print(sb);
	}
}
0