結果

問題 No.1344 Typical Shortest Path Sum
ユーザー tentententen
提出日時 2021-01-18 12:46:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 1,032 bytes
コンパイル時間 4,331 ms
コンパイル使用メモリ 73,740 KB
実行使用メモリ 59,700 KB
最終ジャッジ日時 2023-08-20 20:03:46
合計ジャッジ時間 14,603 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
55,756 KB
testcase_01 AC 104 ms
55,976 KB
testcase_02 AC 103 ms
55,660 KB
testcase_03 AC 111 ms
55,688 KB
testcase_04 AC 110 ms
56,068 KB
testcase_05 AC 102 ms
55,680 KB
testcase_06 AC 105 ms
55,884 KB
testcase_07 AC 107 ms
55,720 KB
testcase_08 AC 107 ms
57,948 KB
testcase_09 AC 110 ms
56,248 KB
testcase_10 AC 104 ms
55,876 KB
testcase_11 AC 101 ms
55,968 KB
testcase_12 AC 103 ms
55,672 KB
testcase_13 AC 103 ms
55,884 KB
testcase_14 AC 112 ms
53,652 KB
testcase_15 AC 104 ms
55,408 KB
testcase_16 AC 125 ms
55,860 KB
testcase_17 AC 104 ms
55,640 KB
testcase_18 AC 104 ms
55,812 KB
testcase_19 AC 104 ms
55,660 KB
testcase_20 AC 109 ms
55,696 KB
testcase_21 AC 106 ms
55,484 KB
testcase_22 AC 105 ms
55,772 KB
testcase_23 AC 109 ms
55,768 KB
testcase_24 AC 108 ms
55,704 KB
testcase_25 AC 110 ms
55,832 KB
testcase_26 AC 107 ms
55,804 KB
testcase_27 AC 109 ms
56,168 KB
testcase_28 AC 106 ms
55,700 KB
testcase_29 AC 107 ms
55,680 KB
testcase_30 AC 105 ms
56,012 KB
testcase_31 AC 102 ms
55,388 KB
testcase_32 AC 101 ms
55,880 KB
testcase_33 AC 102 ms
53,592 KB
testcase_34 AC 103 ms
55,516 KB
testcase_35 AC 103 ms
55,676 KB
testcase_36 AC 102 ms
55,700 KB
testcase_37 AC 108 ms
55,456 KB
testcase_38 AC 104 ms
55,836 KB
testcase_39 AC 109 ms
55,676 KB
testcase_40 AC 138 ms
55,956 KB
testcase_41 AC 136 ms
55,608 KB
testcase_42 AC 136 ms
55,884 KB
testcase_43 AC 130 ms
56,188 KB
testcase_44 AC 130 ms
56,040 KB
testcase_45 AC 140 ms
55,644 KB
testcase_46 AC 133 ms
55,948 KB
testcase_47 AC 136 ms
56,212 KB
testcase_48 AC 148 ms
56,280 KB
testcase_49 AC 131 ms
55,604 KB
testcase_50 AC 131 ms
55,988 KB
testcase_51 AC 135 ms
55,640 KB
testcase_52 AC 141 ms
55,868 KB
testcase_53 AC 166 ms
56,384 KB
testcase_54 AC 131 ms
56,136 KB
testcase_55 AC 134 ms
56,244 KB
testcase_56 AC 139 ms
56,288 KB
testcase_57 AC 141 ms
57,880 KB
testcase_58 AC 139 ms
55,880 KB
testcase_59 AC 133 ms
55,936 KB
testcase_60 AC 141 ms
55,644 KB
testcase_61 AC 107 ms
55,984 KB
testcase_62 AC 182 ms
59,700 KB
testcase_63 AC 169 ms
56,204 KB
testcase_64 AC 171 ms
58,540 KB
testcase_65 AC 184 ms
59,492 KB
testcase_66 AC 182 ms
59,404 KB
testcase_67 AC 182 ms
58,992 KB
testcase_68 AC 157 ms
56,012 KB
testcase_69 AC 155 ms
56,092 KB
testcase_70 AC 109 ms
55,868 KB
testcase_71 AC 103 ms
55,812 KB
testcase_72 AC 101 ms
55,660 KB
testcase_73 AC 99 ms
55,620 KB
testcase_74 AC 102 ms
55,456 KB
testcase_75 AC 104 ms
55,800 KB
testcase_76 AC 103 ms
55,848 KB
testcase_77 AC 104 ms
55,856 KB
testcase_78 AC 108 ms
55,944 KB
testcase_79 AC 111 ms
55,840 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