結果
問題 | No.17 2つの地点に泊まりたい |
ユーザー | rn4ru |
提出日時 | 2016-04-13 03:32:57 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,095 bytes |
コンパイル時間 | 2,179 ms |
コンパイル使用メモリ | 77,940 KB |
実行使用メモリ | 58,108 KB |
最終ジャッジ日時 | 2024-04-15 00:25:46 |
合計ジャッジ時間 | 7,192 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 130 ms
51,944 KB |
testcase_01 | AC | 124 ms
41,324 KB |
testcase_02 | AC | 121 ms
40,160 KB |
testcase_03 | WA | - |
testcase_04 | AC | 179 ms
42,456 KB |
testcase_05 | WA | - |
testcase_06 | AC | 200 ms
43,412 KB |
testcase_07 | AC | 199 ms
43,316 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 130 ms
41,264 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 131 ms
41,272 KB |
testcase_26 | WA | - |
ソースコード
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int[] S = new int[N]; for (int i = 0; i < N; i++) { S[i] = scanner.nextInt(); } int M = scanner.nextInt(); final int INF = Integer.MAX_VALUE / 2; int[][] dist = new int[N][N]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { dist[i][j] = INF; } } for (int i = 0; i < N; i++) { dist[i][i] = 0; } for (int i = 0; i < M; i++) { int A = scanner.nextInt(); int B = scanner.nextInt(); int C = scanner.nextInt(); dist[A][B] = C; dist[B][A] = C; } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) { dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]); } } } int min = INF; for (int i = 1; i < N - 1; i++) { for (int j = 1; j < N - 1; j++) { if (i == j) continue; min = Math.min(min, dist[0][i] + dist[i][j] + dist[j][N - 1] + S[i] + S[j]); } } System.out.println(min); } }