結果

問題 No.1 道のショートカット
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-02 05:31:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 130 ms / 5,000 ms
コード長 894 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 82,408 KB
実行使用メモリ 77,696 KB
最終ジャッジ日時 2024-04-20 00:24:24
合計ジャッジ時間 4,606 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,736 KB
testcase_01 AC 39 ms
52,224 KB
testcase_02 AC 37 ms
52,480 KB
testcase_03 AC 39 ms
52,736 KB
testcase_04 AC 39 ms
52,352 KB
testcase_05 AC 40 ms
52,224 KB
testcase_06 AC 38 ms
52,480 KB
testcase_07 AC 39 ms
52,224 KB
testcase_08 AC 88 ms
76,928 KB
testcase_09 AC 63 ms
66,944 KB
testcase_10 AC 81 ms
75,008 KB
testcase_11 AC 103 ms
77,376 KB
testcase_12 AC 130 ms
77,184 KB
testcase_13 AC 120 ms
77,312 KB
testcase_14 AC 40 ms
52,864 KB
testcase_15 AC 38 ms
52,096 KB
testcase_16 AC 52 ms
63,744 KB
testcase_17 AC 39 ms
52,480 KB
testcase_18 AC 40 ms
53,248 KB
testcase_19 AC 39 ms
52,992 KB
testcase_20 AC 89 ms
76,800 KB
testcase_21 AC 56 ms
64,768 KB
testcase_22 AC 44 ms
52,864 KB
testcase_23 AC 116 ms
77,056 KB
testcase_24 AC 110 ms
77,184 KB
testcase_25 AC 93 ms
76,416 KB
testcase_26 AC 80 ms
73,344 KB
testcase_27 AC 120 ms
77,696 KB
testcase_28 AC 39 ms
52,096 KB
testcase_29 AC 73 ms
71,424 KB
testcase_30 AC 54 ms
63,596 KB
testcase_31 AC 60 ms
65,024 KB
testcase_32 AC 94 ms
76,800 KB
testcase_33 AC 75 ms
72,192 KB
testcase_34 AC 103 ms
76,928 KB
testcase_35 AC 44 ms
59,136 KB
testcase_36 AC 71 ms
70,272 KB
testcase_37 AC 51 ms
61,568 KB
testcase_38 AC 39 ms
52,352 KB
testcase_39 AC 40 ms
52,736 KB
testcase_40 AC 47 ms
60,032 KB
testcase_41 AC 41 ms
52,736 KB
testcase_42 AC 40 ms
52,352 KB
testcase_43 AC 38 ms
52,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

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()))
edge = [[] for _ in range(N)]
for s, t, y, m in zip(S, T, Y, M):
    edge[s-1].append((t-1, y, m))

inf = 10**18
dist = [[inf] * (C + 1) for _ in range(N)]
dist[0][0] = 0
que = [(0, 0, 0)]  # time, cost, pos
while que:
    ds, cs, s = heapq.heappop(que)
    if dist[s][cs] < ds:
        continue
    for t, ct, dt in edge[s]:
        if ct + cs > C:
            continue
        if dist[t][ct + cs] > ds + dt:
            dist[t][ct + cs] = ds + dt
            heapq.heappush(que, (ds + dt, ct + cs, t))

ans = inf
for i in range(C + 1):
    ans = min(ans, dist[N-1][i])
if ans >= inf:
    ans = -1
print(ans)
0