結果

問題 No.1 道のショートカット
ユーザー 👑 SPD_9X2
提出日時 2020-01-21 00:52:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,084 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 79,336 KB
最終ジャッジ日時 2024-07-08 05:20:36
合計ジャッジ時間 3,955 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 36 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

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

Sori = list(map(int,input().split()))
Tori = list(map(int,input().split()))
Yori = list(map(int,input().split()))
Mori = list(map(int,input().split()))

dic = {}

for i in range(V):

    s = Sori[i]-1
    t = Tori[i]-1

    y = Yori[i]
    m = Mori[i]

    if s not in dic:
        dic[s] = []
    if t not in dic:
        dic[t] = []

    dic[s].append([t,y,m])
    dic[t].append([s,y,m])


lis = [[float("inf")] * (C+1) for i in range(N) ]
lis[0][0] = 0

q = deque([])
q.append([0,0])

while len(q) > 0:

    now = q.popleft()
    np = now[0]
    nc = now[1]

    if np not in dic:
        continue

    for i in dic[np]:

        nexp = i[0]
        nexc = i[1]
        dis = i[2]

        if nc + nexc <= C:

            if lis[nexp][nc+nexc] > lis[np][nc] + dis:
                lis[nexp][nc+nexc] = lis[np][nc] + dis
                q.append([nexp,nc+nexc])

ans = float("inf")

for i in range(C+1):

    ans = min(ans , lis[-1][i])

if ans == float("inf"):
    print (-1)
else:
    print (ans)
0