結果

問題 No.17 2つの地点に泊まりたい
ユーザー 37zigen
提出日時 2016-03-07 21:50:50
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,028 bytes
コンパイル時間 2,874 ms
コンパイル使用メモリ 77,564 KB
実行使用メモリ 57,716 KB
最終ジャッジ日時 2024-09-24 15:13:16
合計ジャッジ時間 9,225 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 9
権限があれば一括ダウンロードができます

ソースコード

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