結果

問題 No.17 2つの地点に泊まりたい
ユーザー kou6839kou6839
提出日時 2014-11-23 12:31:08
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 923 bytes
コンパイル時間 1,998 ms
コンパイル使用メモリ 73,828 KB
実行使用メモリ 61,296 KB
最終ジャッジ日時 2023-08-30 22:14:04
合計ジャッジ時間 7,821 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,580 KB
testcase_01 AC 118 ms
56,028 KB
testcase_02 AC 125 ms
55,980 KB
testcase_03 AC 148 ms
56,436 KB
testcase_04 AC 171 ms
55,672 KB
testcase_05 WA -
testcase_06 AC 188 ms
58,520 KB
testcase_07 AC 177 ms
58,464 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 116 ms
55,964 KB
testcase_13 AC 114 ms
55,784 KB
testcase_14 AC 118 ms
55,908 KB
testcase_15 AC 117 ms
55,716 KB
testcase_16 AC 119 ms
56,312 KB
testcase_17 AC 126 ms
55,884 KB
testcase_18 AC 153 ms
56,076 KB
testcase_19 AC 138 ms
55,748 KB
testcase_20 WA -
testcase_21 AC 119 ms
55,496 KB
testcase_22 AC 172 ms
56,364 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 135 ms
56,036 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

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]=100000;
			}
		}
		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[i][j]=Math.min(miti[i][j], miti[i][k]+miti[k][j]);
				}
			}
		}
		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