結果
問題 | No.17 2つの地点に泊まりたい |
ユーザー |
![]() |
提出日時 | 2016-05-09 23:26:51 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 121 ms / 5,000 ms |
コード長 | 687 bytes |
コンパイル時間 | 129 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-10-15 01:34:36 |
合計ジャッジ時間 | 2,813 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
N = int(input()) S = [int(input()) for i in range(N)] M = int(input()) INF = float('inf') costs = [[INF]*N for i in range(N)] for i in range(N): costs[i][i] = 0 for _ in range(M): a, b, c = map(int, input().split()) costs[a][b] = c costs[b][a] = c for k in range(N): for i in range(N): for j in range(N): costs[i][j] = min(costs[i][j], costs[i][k] + costs[k][j]) min_cost = INF for i in range(1, N - 1): for j in range(1, N - 1): if i == j: continue total_cost = costs[0][i] + costs[i][j] + costs[j][N - 1] + S[i] + S[j] if min_cost > total_cost : min_cost = total_cost print(min_cost)