結果

問題 No.17 2つの地点に泊まりたい
ユーザー 37zigen37zigen
提出日時 2016-03-07 21:58:29
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,030 bytes
コンパイル時間 2,446 ms
コンパイル使用メモリ 77,252 KB
実行使用メモリ 61,032 KB
最終ジャッジ日時 2023-10-24 20:16:11
合計ジャッジ時間 7,426 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
57,568 KB
testcase_01 AC 122 ms
57,612 KB
testcase_02 AC 129 ms
57,544 KB
testcase_03 AC 173 ms
57,884 KB
testcase_04 AC 173 ms
57,592 KB
testcase_05 WA -
testcase_06 AC 197 ms
59,796 KB
testcase_07 AC 192 ms
59,660 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 112 ms
56,232 KB
testcase_13 AC 124 ms
57,512 KB
testcase_14 AC 122 ms
57,584 KB
testcase_15 AC 125 ms
57,532 KB
testcase_16 AC 124 ms
57,616 KB
testcase_17 AC 130 ms
57,624 KB
testcase_18 AC 179 ms
58,496 KB
testcase_19 AC 153 ms
57,792 KB
testcase_20 WA -
testcase_21 AC 124 ms
57,520 KB
testcase_22 AC 171 ms
57,892 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 151 ms
57,644 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) throws Exception {
		PrintWriter pw=new PrintWriter(System.out);
		Scanner sc=new Scanner(System.in);

		int n=sc.nextInt();
		int[] stcst=new int[n];

		for(int i=0;i<n;i++){
			stcst[i]=sc.nextInt();
		}
		int[][] mvcst=new int[n][n];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				mvcst[i][j]=1000000;
			}
		}
		int m=sc.nextInt();

		for(int i=0;i<m;i++){
			int from=sc.nextInt();
			int to=sc.nextInt();
			int cst=sc.nextInt();
			mvcst[from][to]=cst;
			mvcst[to][from]=cst;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				for(int k=0;k<n;k++){
					mvcst[i][j]=Math.min(mvcst[i][j], mvcst[i][k]+mvcst[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;
				int tmp=mvcst[i][0]+mvcst[i][j]+mvcst[n-1][j]+stcst[i]+stcst[j];
				ans=Math.min(tmp, ans);
			}
		}
		pw.println(ans);
		pw.close();
		sc.close();
	} 

}
0