結果

問題 No.1 道のショートカット
ユーザー titia
提出日時 2021-11-01 14:19:18
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 709 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2024-10-10 02:54:11
合計ジャッジ時間 5,145 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 36 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

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()))

E=[[] for i in range(N+1)]

for i in range(V):
    E[S[i]].append((T[i],Y[i],M[i]))
    E[T[i]].append((S[i],Y[i],M[i]))

DP=[[1<<30]*(C+1) for i in range(N+1)]

DP[1][C]=0

Q=[(0,1,C)]

while Q:
    now,town,money=heapq.heappop(Q)
    if now>DP[town][money]:
        continue

    for to,y,m in E[town]:
        if money-y>=0 and DP[to][money-y]>now+m:
            DP[to][money-y]=now+m
            heapq.heappush(Q,(now+m,to,money-y))

MIN=min(DP[N])

if MIN==1<<30:
    print(-1)
else:
    print(MIN)
            
0