結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
41,224 KB
testcase_01 AC 101 ms
41,556 KB
testcase_02 AC 115 ms
41,500 KB
testcase_03 AC 143 ms
41,684 KB
testcase_04 AC 161 ms
42,108 KB
testcase_05 AC 204 ms
44,496 KB
testcase_06 AC 188 ms
43,456 KB
testcase_07 AC 188 ms
42,672 KB
testcase_08 AC 208 ms
45,252 KB
testcase_09 AC 206 ms
45,724 KB
testcase_10 AC 184 ms
42,828 KB
testcase_11 AC 191 ms
43,640 KB
testcase_12 AC 122 ms
41,520 KB
testcase_13 AC 117 ms
40,240 KB
testcase_14 AC 111 ms
41,728 KB
testcase_15 AC 117 ms
40,252 KB
testcase_16 AC 126 ms
41,392 KB
testcase_17 AC 139 ms
41,296 KB
testcase_18 AC 158 ms
41,580 KB
testcase_19 AC 142 ms
41,576 KB
testcase_20 AC 136 ms
41,448 KB
testcase_21 AC 136 ms
41,376 KB
testcase_22 AC 160 ms
42,204 KB
testcase_23 AC 199 ms
44,092 KB
testcase_24 AC 192 ms
43,412 KB
testcase_25 AC 135 ms
41,900 KB
testcase_26 AC 193 ms
44,904 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