結果
| 問題 |
No.17 2つの地点に泊まりたい
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-11-12 03:47:06 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 228 ms / 5,000 ms |
| コード長 | 1,140 bytes |
| コンパイル時間 | 2,566 ms |
| コンパイル使用メモリ | 77,132 KB |
| 実行使用メモリ | 45,656 KB |
| 最終ジャッジ日時 | 2024-10-15 01:17:43 |
| 合計ジャッジ時間 | 8,725 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
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);
}
}