結果
| 問題 | No.17 2つの地点に泊まりたい | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-03-12 12:43:12 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 141 ms / 5,000 ms | 
| コード長 | 926 bytes | 
| コンパイル時間 | 707 ms | 
| コンパイル使用メモリ | 82,048 KB | 
| 実行使用メモリ | 77,948 KB | 
| 最終ジャッジ日時 | 2024-09-16 18:44:54 | 
| 合計ジャッジ時間 | 3,647 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge6 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 | 
ソースコード
from collections import defaultdict
from heapq import heappop, heappush
n = int(input())
P = [int(input()) for _ in range(n)]
m = int(input())
Edge = defaultdict(list)
for _ in range(m):
    a, b, c = map(int, input().split())
    Edge[a].append((b, c))
    Edge[b].append((a, c))
INF = 10**18
C = [[INF for _ in range(n)] for _ in range(n)]
for i in range(n):
    C[i][i] = 0
    Heap = [(0, i, -1)]
    while Heap:
        cost, curr, prev = heappop(Heap)
        if cost > C[i][curr]:
            continue
        for np, d in Edge[curr]:
            if np == prev:
                continue
            if cost + d > C[i][np]:
                continue
            C[i][np] = cost + d
            heappush(Heap, (cost + d, np, curr))
ans = INF
for i in range(1, n - 1):
    for j in range(1, n - 1):
        if i == j:
            continue
        ans = min(ans, C[0][i] + P[i] + C[i][j] + P[j] + C[j][n - 1])
print(ans)
            
            
            
        