結果

問題 No.17 2つの地点に泊まりたい
ユーザー rn4rurn4ru
提出日時 2016-04-13 03:40:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 212 ms / 5,000 ms
コード長 1,095 bytes
コンパイル時間 2,013 ms
コンパイル使用メモリ 74,088 KB
実行使用メモリ 59,348 KB
最終ジャッジ日時 2023-08-05 03:45:46
合計ジャッジ時間 7,539 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,544 KB
testcase_01 AC 119 ms
55,824 KB
testcase_02 AC 128 ms
55,536 KB
testcase_03 AC 152 ms
55,784 KB
testcase_04 AC 173 ms
55,808 KB
testcase_05 AC 199 ms
58,572 KB
testcase_06 AC 193 ms
58,556 KB
testcase_07 AC 187 ms
58,648 KB
testcase_08 AC 211 ms
58,988 KB
testcase_09 AC 212 ms
59,348 KB
testcase_10 AC 191 ms
57,004 KB
testcase_11 AC 201 ms
58,580 KB
testcase_12 AC 119 ms
56,052 KB
testcase_13 AC 119 ms
56,128 KB
testcase_14 AC 124 ms
55,704 KB
testcase_15 AC 123 ms
55,808 KB
testcase_16 AC 122 ms
55,964 KB
testcase_17 AC 128 ms
55,772 KB
testcase_18 AC 161 ms
55,996 KB
testcase_19 AC 141 ms
56,056 KB
testcase_20 AC 127 ms
54,716 KB
testcase_21 AC 123 ms
55,776 KB
testcase_22 AC 154 ms
55,964 KB
testcase_23 AC 198 ms
58,876 KB
testcase_24 AC 195 ms
58,392 KB
testcase_25 AC 137 ms
55,624 KB
testcase_26 AC 203 ms
58,896 KB
権限があれば一括ダウンロードができます

ソースコード

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 k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					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