結果

問題 No.1 道のショートカット
ユーザー maninimanini
提出日時 2021-02-12 15:01:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 185 ms / 5,000 ms
コード長 1,438 bytes
コンパイル時間 468 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 79,772 KB
最終ジャッジ日時 2023-09-26 13:57:17
合計ジャッジ時間 7,055 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,096 KB
testcase_01 AC 76 ms
71,296 KB
testcase_02 AC 80 ms
71,472 KB
testcase_03 AC 76 ms
71,276 KB
testcase_04 AC 76 ms
71,232 KB
testcase_05 AC 74 ms
71,260 KB
testcase_06 AC 75 ms
71,236 KB
testcase_07 AC 75 ms
71,228 KB
testcase_08 AC 125 ms
78,064 KB
testcase_09 AC 96 ms
76,552 KB
testcase_10 AC 128 ms
78,580 KB
testcase_11 AC 148 ms
78,988 KB
testcase_12 AC 172 ms
79,340 KB
testcase_13 AC 174 ms
79,216 KB
testcase_14 AC 76 ms
71,284 KB
testcase_15 AC 75 ms
71,124 KB
testcase_16 AC 90 ms
77,428 KB
testcase_17 AC 76 ms
71,344 KB
testcase_18 AC 78 ms
71,120 KB
testcase_19 AC 77 ms
71,260 KB
testcase_20 AC 123 ms
78,060 KB
testcase_21 AC 92 ms
76,452 KB
testcase_22 AC 78 ms
71,288 KB
testcase_23 AC 165 ms
79,772 KB
testcase_24 AC 159 ms
79,192 KB
testcase_25 AC 140 ms
78,892 KB
testcase_26 AC 125 ms
77,748 KB
testcase_27 AC 185 ms
79,540 KB
testcase_28 AC 75 ms
71,124 KB
testcase_29 AC 110 ms
78,128 KB
testcase_30 AC 87 ms
76,772 KB
testcase_31 AC 92 ms
76,628 KB
testcase_32 AC 127 ms
78,368 KB
testcase_33 AC 117 ms
78,216 KB
testcase_34 AC 150 ms
78,948 KB
testcase_35 AC 78 ms
75,804 KB
testcase_36 AC 99 ms
76,756 KB
testcase_37 AC 82 ms
76,444 KB
testcase_38 AC 73 ms
71,276 KB
testcase_39 AC 82 ms
71,408 KB
testcase_40 AC 81 ms
76,424 KB
testcase_41 AC 75 ms
71,240 KB
testcase_42 AC 76 ms
71,184 KB
testcase_43 AC 77 ms
71,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding:UTF-8
import sys
from heapq import heappush, heappop

MOD = 10 ** 9 + 7
INF = float('inf')

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()))     # スペース区切り連続数字

# ダイクストラ O((E+N)logN)
dist = [[] for _ in range(N)]    # dist[n]: ノード n に隣接する(ノード, 重み)をリストで持つ
for i in range(V):
    s = S[i] - 1
    t = T[i] - 1
    c = Y[i]
    d = M[i]
    dist[s].append((t, c, d))
    # dist[t].append((s, c, d))

ns = 0
hq = [(0, C, 0)]   # (distance, node)
dist_min = [[INF] * (C + 1) for _ in range(N)]
dist_min[ns][C] = 0
seen = [[False] * (C + 1) for _ in range(N)]

while hq:
    d, c, v = heappop(hq)   # ノードを pop する
    if seen[v][c]:
        continue
    seen[v][c] = True
    for to, cost, dis in dist[v]:    # ノード v に隣接しているノードに対して
        if c - cost >= 0 and seen[to][c - cost] == False and d + dis < dist_min[to][c - cost]:
            dist_min[to][c - cost] = d + dis
            heappush(hq, (dist_min[to][c - cost], c - cost, to))

res = min(dist_min[N-1])
if res == INF:
    res = -1
print("{}".format(res))
0