結果
| 問題 |
No.17 2つの地点に泊まりたい
|
| コンテスト | |
| ユーザー |
ぴろず
|
| 提出日時 | 2014-12-19 13:59:44 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 205 ms / 5,000 ms |
| コード長 | 935 bytes |
| コンパイル時間 | 2,321 ms |
| コンパイル使用メモリ | 76,524 KB |
| 実行使用メモリ | 45,940 KB |
| 最終ジャッジ日時 | 2024-10-15 01:17:59 |
| 合計ジャッジ時間 | 6,940 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
package no017;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
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[][] dist = new int[n][n];
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
if (i != j) {
dist[i][j] = 1 << 29;
}
}
}
for(int i=0;i<m;i++) {
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
dist[a][b] = dist[b][a] = c;
}
for(int k=0;k<n;k++) {
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
int ans = 1 << 29;
for(int i=1;i<n-1;i++) {
for(int j=1;j<n-1;j++) {
if (i == j) {
continue;
}
ans = Math.min(ans, dist[0][i]+dist[i][j]+dist[j][n-1]+s[i]+s[j]);;
}
}
System.out.println(ans);
}
}
ぴろず