結果

問題 No.1 道のショートカット
ユーザー ryusukeryusuke
提出日時 2022-01-28 19:58:40
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,184 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 86,812 KB
実行使用メモリ 76,500 KB
最終ジャッジ日時 2023-08-28 17:24:53
合計ジャッジ時間 5,912 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,292 KB
testcase_01 AC 76 ms
71,336 KB
testcase_02 AC 76 ms
71,184 KB
testcase_03 AC 74 ms
71,088 KB
testcase_04 AC 76 ms
71,180 KB
testcase_05 AC 77 ms
70,996 KB
testcase_06 AC 76 ms
71,016 KB
testcase_07 AC 74 ms
71,312 KB
testcase_08 AC 83 ms
76,144 KB
testcase_09 AC 79 ms
75,492 KB
testcase_10 AC 80 ms
76,108 KB
testcase_11 AC 86 ms
76,348 KB
testcase_12 WA -
testcase_13 AC 85 ms
76,272 KB
testcase_14 WA -
testcase_15 AC 74 ms
71,008 KB
testcase_16 WA -
testcase_17 AC 74 ms
71,240 KB
testcase_18 AC 76 ms
71,136 KB
testcase_19 AC 76 ms
70,996 KB
testcase_20 AC 79 ms
75,416 KB
testcase_21 AC 74 ms
71,340 KB
testcase_22 AC 74 ms
71,140 KB
testcase_23 AC 84 ms
76,256 KB
testcase_24 AC 84 ms
76,500 KB
testcase_25 AC 77 ms
75,468 KB
testcase_26 AC 75 ms
71,276 KB
testcase_27 AC 85 ms
76,376 KB
testcase_28 AC 75 ms
71,020 KB
testcase_29 WA -
testcase_30 AC 78 ms
75,456 KB
testcase_31 AC 83 ms
76,292 KB
testcase_32 WA -
testcase_33 AC 80 ms
75,440 KB
testcase_34 WA -
testcase_35 AC 80 ms
75,492 KB
testcase_36 WA -
testcase_37 AC 81 ms
76,156 KB
testcase_38 AC 76 ms
71,152 KB
testcase_39 AC 78 ms
71,188 KB
testcase_40 WA -
testcase_41 AC 76 ms
71,016 KB
testcase_42 AC 75 ms
71,160 KB
testcase_43 AC 76 ms
71,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop, heapify
import sys
input = sys.stdin.readline

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):
    s[i] -= 1
    t[i] -= 1
    g[s[i]].append((m[i], y[i], t[i])) # 時間・コスト・行き先
#print('g:のグラフ')
#print(*g, sep='\n')

INF = 10 ** 18
dist = [INF] * n # かかる時間
cost = [INF] * n # 必要なコスト
dist[0] = 0
cost[0] = 0
q = [(0, 0, 0)] # 時間・コスト・今いる場所
heapify(q)

while q:
    pre_time, pre_cost, pre_ind = heappop(q)
    for nxt_time, nxt_cost, nxt_ind in g[pre_ind]:
        if dist[nxt_ind] <= dist[pre_ind] + nxt_time: continue
        if cost[pre_ind] + nxt_cost > c: continue
        dist[nxt_ind] = dist[pre_ind] + nxt_time
        cost[nxt_ind] = cost[pre_ind] + nxt_cost
        heappush(q, (dist[nxt_ind], cost[nxt_ind], nxt_ind))
        #print(dist)
        #print(cost)
        #print(q)
        #print()

##print(dist)
#print(cost)
print(dist[-1]) if dist[-1] != INF else print(-1)
0