結果

問題 No.1 道のショートカット
ユーザー syunsuke1024
提出日時 2020-05-05 10:53:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 836 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 82,116 KB
実行使用メモリ 87,572 KB
最終ジャッジ日時 2024-07-08 05:23:06
合計ジャッジ時間 4,559 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 39 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
C=int(input())
V=int(input())

S=list(map(int,input().split()))
T=list(map(int,input().split()))
Cost=list(map(int,input().split()))
Time=list(map(int,input().split()))

L=[[]for i in range(N+1)]
for i in range(V):
    L[S[i]].append([Time[i],Cost[i],T[i]])

DP=[[10**9 for i in range(C+1)]for j in range(N+1)]

DP[1][0]=0
#print(DP)

import heapq
Q=[]
for time,cost,t in L[1]:
    if cost<=C:
        Q.append((time,cost,t))

heapq.heapify(Q)
for i in range(10**7):
    if len(Q)==0:
        break
    time,cost,t=heapq.heappop(Q)
    if DP[t][cost]==10**9:
        DP[t][cost]=time
        for fortime,forcost,fort in L[t]:
            if cost+forcost<=C and DP[t][cost+forcost]==10**9:
                heapq.heappush(Q,(time+fortime,cost+forcost,fort))
if min(DP[-1])==10**9:
    print(-1)
else:
    print(min(DP[-1]))
0