結果

問題 No.1449 新プロランド
ユーザー gorugo30
提出日時 2021-05-08 17:37:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 742 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 82,360 KB
実行使用メモリ 80,668 KB
最終ジャッジ日時 2024-12-24 02:08:18
合計ジャッジ時間 5,035 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
adj = [[] for i in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    A -= 1
    B -= 1
    adj[A].append((B, C))
    adj[B].append((A, C))
T = list(map(int, input().split()))

dist = [[-1] * 1002 for i in range(N)]
dist[0][0] = 0
import heapq
pq = [(0, 0, 0)]
while len(pq):
    d, v, p = heapq.heappop(pq)
    if d > dist[v][p]:
        continue
    for nv, c in adj[v]:
        np = min(1001, T[v] + p)
        nd = d + T[v] + c // np
        if dist[nv][np] == -1 or dist[nv][np] > nd:
            dist[nv][np] = nd
            heapq.heappush(pq, (nd, nv, np))
ans = 10 ** 10
for i in range(1002):
    if dist[-1][i] == -1:
        continue
    ans = min(ans, dist[-1][i])
print(ans)
0