結果
| 問題 | No.17 2つの地点に泊まりたい | 
| コンテスト | |
| ユーザー |  nbisco | 
| 提出日時 | 2016-04-17 18:06:41 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 116 ms / 5,000 ms | 
| コード長 | 798 bytes | 
| コンパイル時間 | 286 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 11,008 KB | 
| 最終ジャッジ日時 | 2024-10-15 01:33:58 | 
| 合計ジャッジ時間 | 2,755 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 | 
ソースコード
#!/usr/bin/env python3
#fileencoding: utf-8
N = int(input())
S = [int(input()) for i in range(N)]
costs = [[int(j) for j in input().strip().split(" ")] for i in range(int(input()))]
cost_map = [[1<<31]*N for i in range(N)]
for cost in costs:
    cost_map[cost[0]][cost[1]] = cost[2]
    cost_map[cost[1]][cost[0]] = cost[2]
# warshall_froyd
for i in range(N):  # 経由
    for j in range(N): # start
        for k in range(N): # goal
            if j == k:
                cost_map[j][k] = 0
            else:
                cost_map[j][k] = min(cost_map[j][k],cost_map[j][i]+cost_map[i][k])
result = 1000000
for i in range(1,N-1):
    for j in range(1,N-1):
        if i != j:
            result = min(result, cost_map[0][i] + cost_map[i][j] + cost_map[j][N-1] + S[i] + S[j])
print(result)
            
            
            
        