結果

問題 No.17 2つの地点に泊まりたい
ユーザー ぴろずぴろず
提出日時 2014-12-19 13:59:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 212 ms / 5,000 ms
コード長 935 bytes
コンパイル時間 2,377 ms
コンパイル使用メモリ 77,236 KB
実行使用メモリ 57,664 KB
最終ジャッジ日時 2024-04-23 02:00:22
合計ジャッジ時間 7,100 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
53,988 KB
testcase_01 AC 117 ms
53,948 KB
testcase_02 AC 137 ms
54,136 KB
testcase_03 AC 159 ms
54,120 KB
testcase_04 AC 180 ms
54,500 KB
testcase_05 AC 212 ms
56,736 KB
testcase_06 AC 188 ms
56,720 KB
testcase_07 AC 188 ms
56,828 KB
testcase_08 AC 199 ms
57,664 KB
testcase_09 AC 206 ms
57,480 KB
testcase_10 AC 205 ms
54,368 KB
testcase_11 AC 194 ms
56,672 KB
testcase_12 AC 112 ms
53,492 KB
testcase_13 AC 110 ms
53,172 KB
testcase_14 AC 127 ms
53,968 KB
testcase_15 AC 124 ms
53,952 KB
testcase_16 AC 130 ms
53,908 KB
testcase_17 AC 132 ms
54,184 KB
testcase_18 AC 158 ms
54,544 KB
testcase_19 AC 137 ms
54,164 KB
testcase_20 AC 129 ms
54,188 KB
testcase_21 AC 133 ms
54,136 KB
testcase_22 AC 167 ms
54,368 KB
testcase_23 AC 190 ms
56,748 KB
testcase_24 AC 191 ms
56,956 KB
testcase_25 AC 126 ms
54,124 KB
testcase_26 AC 188 ms
56,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no017;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] s = new int[n];
		for(int i=0;i<n;i++) {
			s[i] = sc.nextInt();
		}
		int m = sc.nextInt();
		int[][] dist = new int[n][n];
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				if (i != j) {
					dist[i][j] = 1 << 29;
				}
			}
		}
		for(int i=0;i<m;i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			dist[a][b] = 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 ans = 1 << 29;
		for(int i=1;i<n-1;i++) {
			for(int j=1;j<n-1;j++) {
				if (i == j) {
					continue;
				}
				ans = Math.min(ans, dist[0][i]+dist[i][j]+dist[j][n-1]+s[i]+s[j]);;
			}
		}
		System.out.println(ans);
	}

}
0