結果

問題 No.1 道のショートカット
ユーザー aaaaaaaaaa2230
提出日時 2021-04-05 10:05:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 672 bytes
コンパイル時間 742 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 79,480 KB
最終ジャッジ日時 2024-12-30 12:06:51
合計ジャッジ時間 7,231 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 36 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush
n = int(input())
c = int(input())
v = int(input())
L = [list(map(int,input().split())) for i in range(4)]

e = [[] for i in range(n)]
for s,t,y,m in zip(L[0],L[1],L[2],L[3]):
    s -= 1
    t -= 1
    e[s].append((t,y,m))
    e[t].append((s,y,m))

inf = 10**10
dis = [[inf]*(c+1) for i in range(n)]
dis[0][c] = 0
q = [(0,0,c)]
while q:
    time,now,d = heappop(q)
    if time > dis[now][d]:
        continue
    for nex,y,m in e[now]:
        if d >= y and dis[nex][d-y] > dis[now][d]+m:
            dis[nex][d-y] = dis[now][d]+m
            heappush(q, (dis[nex][d-y],nex,d-y))
ans = min(dis[-1])
if ans == inf:
    ans = -1
print(ans)
0