結果

問題 No.17 2つの地点に泊まりたい
ユーザー htensaihtensai
提出日時 2020-01-24 17:46:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 209 ms / 5,000 ms
コード長 1,495 bytes
コンパイル時間 1,995 ms
コンパイル使用メモリ 75,328 KB
実行使用メモリ 59,420 KB
最終ジャッジ日時 2023-10-12 04:13:00
合計ジャッジ時間 7,399 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,780 KB
testcase_01 AC 119 ms
55,640 KB
testcase_02 AC 123 ms
55,724 KB
testcase_03 AC 155 ms
55,988 KB
testcase_04 AC 168 ms
55,900 KB
testcase_05 AC 189 ms
58,924 KB
testcase_06 AC 187 ms
58,152 KB
testcase_07 AC 178 ms
58,372 KB
testcase_08 AC 207 ms
59,384 KB
testcase_09 AC 209 ms
59,420 KB
testcase_10 AC 190 ms
58,600 KB
testcase_11 AC 196 ms
59,188 KB
testcase_12 AC 139 ms
55,908 KB
testcase_13 AC 116 ms
56,088 KB
testcase_14 AC 118 ms
55,788 KB
testcase_15 AC 115 ms
55,428 KB
testcase_16 AC 118 ms
55,812 KB
testcase_17 AC 127 ms
55,776 KB
testcase_18 AC 138 ms
56,076 KB
testcase_19 AC 139 ms
55,784 KB
testcase_20 AC 124 ms
56,204 KB
testcase_21 AC 122 ms
55,864 KB
testcase_22 AC 152 ms
56,288 KB
testcase_23 AC 197 ms
58,836 KB
testcase_24 AC 196 ms
58,644 KB
testcase_25 AC 133 ms
55,488 KB
testcase_26 AC 199 ms
59,320 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[][] costs = new int[n][n];
        for (int i = 0; i < n; i++) {
            Arrays.fill(costs[i], Integer.MAX_VALUE / 10);
            costs[i][i] = 0;
        }
        int[] stays = new int[n];
        for (int i = 0; i < n; i++) {
            stays[i] = sc.nextInt();
        }
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            costs[a][b] = c;
            costs[b][a] = c;
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) {
                    continue;
                }
                for (int k = 0; k < n; k++) {
                    if (i == k || j == k) {
                        continue;
                    }
                    costs[j][k] = Math.min(costs[j][k], costs[j][i] + costs[i][k]);
                }
            }
        }
        int min = Integer.MAX_VALUE;
        for (int i = 1; i < n - 1; i++) {
            for (int j = 1; j < n - 1; j++) {
                if (i == j) {
                    continue;
                }
                min = Math.min(min, costs[0][i] + stays[i] + costs[i][j] + stays[j] + costs[j][n - 1]);
            }
        }
        System.out.println(min);
    }
}
0