結果

問題 No.17 2つの地点に泊まりたい
ユーザー tentententen
提出日時 2020-11-26 20:21:12
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,060 bytes
コンパイル時間 4,512 ms
コンパイル使用メモリ 73,404 KB
実行使用メモリ 59,728 KB
最終ジャッジ日時 2023-10-01 03:28:47
合計ジャッジ時間 7,656 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
55,716 KB
testcase_01 AC 123 ms
55,756 KB
testcase_02 AC 120 ms
55,884 KB
testcase_03 AC 157 ms
55,904 KB
testcase_04 AC 173 ms
56,880 KB
testcase_05 AC 198 ms
58,984 KB
testcase_06 AC 186 ms
58,016 KB
testcase_07 AC 182 ms
58,532 KB
testcase_08 AC 200 ms
59,728 KB
testcase_09 AC 200 ms
59,008 KB
testcase_10 AC 190 ms
56,404 KB
testcase_11 AC 194 ms
58,896 KB
testcase_12 AC 117 ms
55,608 KB
testcase_13 AC 118 ms
55,964 KB
testcase_14 AC 121 ms
55,484 KB
testcase_15 AC 119 ms
56,020 KB
testcase_16 AC 119 ms
56,292 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 195 ms
58,580 KB
testcase_24 AC 192 ms
58,608 KB
testcase_25 AC 133 ms
56,204 KB
testcase_26 AC 199 ms
58,644 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[] stays = new int[n];
		int[][] costs = new int[n][n];
		for (int i = 0; i < n; i++) {
		    Arrays.fill(costs[i], Integer.MAX_VALUE / 3);
		    costs[i][i] = 0;
		    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++) {
		        for (int k = 0; k < n; k++) {
		            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] + costs[i][j] + costs[j][n - 1] + stays[i] + stays[j]);
		    }
		}
		System.out.println(min);
	}
}

0