結果

問題 No.17 2つの地点に泊まりたい
ユーザー rn4rurn4ru
提出日時 2016-04-13 03:35:50
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,095 bytes
コンパイル時間 2,194 ms
コンパイル使用メモリ 77,856 KB
実行使用メモリ 57,700 KB
最終ジャッジ日時 2024-04-15 00:26:57
合計ジャッジ時間 7,770 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
54,300 KB
testcase_01 AC 129 ms
41,596 KB
testcase_02 AC 137 ms
41,660 KB
testcase_03 AC 165 ms
41,924 KB
testcase_04 AC 180 ms
42,148 KB
testcase_05 WA -
testcase_06 AC 203 ms
43,852 KB
testcase_07 AC 195 ms
43,276 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 117 ms
40,220 KB
testcase_13 AC 130 ms
41,676 KB
testcase_14 AC 133 ms
41,324 KB
testcase_15 AC 115 ms
40,300 KB
testcase_16 AC 132 ms
41,712 KB
testcase_17 AC 138 ms
41,420 KB
testcase_18 AC 175 ms
42,008 KB
testcase_19 AC 146 ms
42,144 KB
testcase_20 WA -
testcase_21 AC 134 ms
41,632 KB
testcase_22 AC 179 ms
41,948 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 142 ms
41,368 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] S = new int[N];
		for (int i = 0; i < N; i++) {
			S[i] = scanner.nextInt();
		}
		int M = scanner.nextInt();
		final int INF = Integer.MAX_VALUE / 4;
		int[][] dist = new int[N][N];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				dist[i][j] = INF;
			}
		}
		for (int i = 0; i < N; i++) {
			dist[i][i] = 0;
		}
		for (int i = 0; i < M; i++) {
			int A = scanner.nextInt();
			int B = scanner.nextInt();
			int C = scanner.nextInt();
			dist[A][B] = C;
			dist[B][A] = C;
		}

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				for (int k = 0; k < N; k++) {
					dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}

		int min = INF;
		for (int i = 1; i < N - 1; i++) {
			for (int j = 1; j < N - 1; j++) {
				if (i == j)
					continue;
				min = Math.min(min, dist[0][i] + dist[i][j] + dist[j][N - 1] + S[i] + S[j]);
			}
		}

		System.out.println(min);
	}

}
0