結果

問題 No.17 2つの地点に泊まりたい
ユーザー scachescache
提出日時 2014-11-12 03:47:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 204 ms / 5,000 ms
コード長 1,140 bytes
コンパイル時間 1,925 ms
コンパイル使用メモリ 76,984 KB
実行使用メモリ 45,452 KB
最終ジャッジ日時 2024-04-23 02:00:05
合計ジャッジ時間 6,760 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
41,332 KB
testcase_01 AC 113 ms
41,280 KB
testcase_02 AC 109 ms
41,796 KB
testcase_03 AC 155 ms
41,824 KB
testcase_04 AC 160 ms
42,324 KB
testcase_05 AC 188 ms
43,900 KB
testcase_06 AC 178 ms
43,516 KB
testcase_07 AC 180 ms
43,264 KB
testcase_08 AC 194 ms
45,452 KB
testcase_09 AC 204 ms
45,196 KB
testcase_10 AC 182 ms
42,704 KB
testcase_11 AC 186 ms
43,380 KB
testcase_12 AC 120 ms
40,240 KB
testcase_13 AC 114 ms
40,192 KB
testcase_14 AC 118 ms
41,520 KB
testcase_15 AC 104 ms
41,592 KB
testcase_16 AC 118 ms
41,156 KB
testcase_17 AC 129 ms
41,800 KB
testcase_18 AC 131 ms
41,800 KB
testcase_19 AC 134 ms
41,772 KB
testcase_20 AC 129 ms
41,704 KB
testcase_21 AC 108 ms
40,228 KB
testcase_22 AC 158 ms
42,072 KB
testcase_23 AC 185 ms
43,968 KB
testcase_24 AC 180 ms
43,512 KB
testcase_25 AC 124 ms
41,608 KB
testcase_26 AC 186 ms
44,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

/**
 * 
 * @author scache
 *
 */
public class Main {
	public static void main(String[] args) {
		Main p = new Main();
	}

	public Main() {
		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[][] routes = new int[n][n];
		for(int i=0;i<n;i++)
			Arrays.fill(routes[i], 10000000);
		
		for(int i=0;i<m;i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			routes[a][b] = routes[b][a] = sc.nextInt();
		}
		solve(s, routes);
	}
	
	public void solve(int[] s, int[][] routes) {
		
		for(int k=0;k<s.length;k++){
			for(int i=0;i<s.length;i++){
				for(int j=0;j<s.length;j++){
					routes[i][j] = Math.min(routes[i][j], routes[i][k]+routes[k][j]);
				}
			}
		}
		
		int res = Integer.MAX_VALUE;
		for(int i=1;i<s.length-1;i++){
			for(int j=1;j<s.length-1;j++){
				if(i==j)
					continue;
				res = Math.min(res, routes[0][i]+routes[i][j]+routes[j][s.length-1]+s[i]+s[j]);
			}
		}
		
		System.out.println(res);
	}
}
0