結果

問題 No.17 2つの地点に泊まりたい
ユーザー kou6839kou6839
提出日時 2014-11-23 12:42:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 207 ms / 5,000 ms
コード長 925 bytes
コンパイル時間 2,234 ms
コンパイル使用メモリ 77,364 KB
実行使用メモリ 45,548 KB
最終ジャッジ日時 2024-10-15 01:17:51
合計ジャッジ時間 7,402 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
39,956 KB
testcase_01 AC 115 ms
40,888 KB
testcase_02 AC 118 ms
41,064 KB
testcase_03 AC 163 ms
41,376 KB
testcase_04 AC 159 ms
42,396 KB
testcase_05 AC 192 ms
43,884 KB
testcase_06 AC 184 ms
43,176 KB
testcase_07 AC 183 ms
43,040 KB
testcase_08 AC 207 ms
45,548 KB
testcase_09 AC 205 ms
45,436 KB
testcase_10 AC 187 ms
42,208 KB
testcase_11 AC 190 ms
42,588 KB
testcase_12 AC 119 ms
40,868 KB
testcase_13 AC 116 ms
40,852 KB
testcase_14 AC 121 ms
40,564 KB
testcase_15 AC 119 ms
40,820 KB
testcase_16 AC 116 ms
40,884 KB
testcase_17 AC 126 ms
41,188 KB
testcase_18 AC 162 ms
41,176 KB
testcase_19 AC 136 ms
40,932 KB
testcase_20 AC 128 ms
40,840 KB
testcase_21 AC 109 ms
40,080 KB
testcase_22 AC 143 ms
41,240 KB
testcase_23 AC 193 ms
43,456 KB
testcase_24 AC 190 ms
43,180 KB
testcase_25 AC 131 ms
41,000 KB
testcase_26 AC 193 ms
44,476 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[] s = new int[n];
		for(int i=0;i<n;i++){
			s[i]=sc.nextInt();
		}
		int m = sc.nextInt();
		int[][] miti=new int[n][n];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==j)miti[i][j]=0;
				else miti[i][j]=10000000;
			}
		}
		for(int i=0;i<m;i++){
			int a=sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			miti[a][b]=miti[b][a]=c;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				for(int k=0;k<n;k++){
					miti[j][k]=Math.min(miti[j][k], miti[j][i]+miti[i][k]);
				}
			}
		}
		int ans=Integer.MAX_VALUE;
		for(int i=1;i<n-1;i++){
			for(int j=1;j<n-1;j++){
				if(i==j) continue;
				ans=Math.min(ans, miti[0][i]+miti[i][j]+miti[j][n-1]+s[i]+s[j]);
			}
		}
		System.out.println(ans);
	}
}	
0