結果

問題 No.1 道のショートカット
ユーザー pessimist
提出日時 2025-06-07 14:54:47
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 663 bytes
コンパイル時間 574 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 211,024 KB
最終ジャッジ日時 2025-06-07 14:55:09
合計ジャッジ時間 20,942 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14 WA * 5 TLE * 1 -- * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

INF=10**10
N=int(input())
C=int(input())
V=int(input())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
Y=list(map(int,input().split()))
M=list(map(int,input().split()))
g=[[] for _ in range(N)]
for i in range(V):
    g[S[i]-1].append([T[i]-1,Y[i],M[i]])
    g[T[i]-1].append([S[i]-1,Y[i],M[i]])

from heapq import heappop, heappush, heapify
heap=[(0,C,0)]
heapify(heap)
dp=[[INF for _ in range(C+1)] for _ in range(N)]
while heap:
    mm,cc,u = heappop(heap)
    dp[u][cc]=mm
    for v,y,m in g[u]:
        if cc-y<0:continue
        if dp[v][cc-y]>mm+m:
            heappush(heap,(mm+m,cc-y,v))
print(-1 if min(dp[N-1])==INF else min(dp[N-1]))
0