結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
57,716 KB
testcase_01 AC 122 ms
57,616 KB
testcase_02 AC 126 ms
55,552 KB
testcase_03 AC 148 ms
57,776 KB
testcase_04 AC 176 ms
57,720 KB
testcase_05 WA -
testcase_06 AC 192 ms
60,000 KB
testcase_07 AC 183 ms
59,940 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 125 ms
57,628 KB
testcase_13 AC 121 ms
57,560 KB
testcase_14 AC 122 ms
57,636 KB
testcase_15 AC 123 ms
57,672 KB
testcase_16 AC 119 ms
57,568 KB
testcase_17 AC 135 ms
57,656 KB
testcase_18 AC 161 ms
57,944 KB
testcase_19 AC 132 ms
57,596 KB
testcase_20 WA -
testcase_21 AC 117 ms
56,268 KB
testcase_22 AC 150 ms
57,960 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 132 ms
57,628 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]=10000;
			}
		}
		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