結果

問題 No.1 道のショートカット
ユーザー iseeisee
提出日時 2022-12-03 20:38:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 1,254 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,352 KB
実行使用メモリ 77,360 KB
最終ジャッジ日時 2024-04-19 07:34:13
合計ジャッジ時間 4,271 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,344 KB
testcase_01 AC 40 ms
53,152 KB
testcase_02 AC 40 ms
54,356 KB
testcase_03 AC 37 ms
53,076 KB
testcase_04 AC 39 ms
54,388 KB
testcase_05 AC 37 ms
53,580 KB
testcase_06 AC 38 ms
54,860 KB
testcase_07 AC 38 ms
53,300 KB
testcase_08 AC 90 ms
76,856 KB
testcase_09 AC 64 ms
67,780 KB
testcase_10 AC 85 ms
77,004 KB
testcase_11 AC 102 ms
76,868 KB
testcase_12 AC 121 ms
77,244 KB
testcase_13 AC 118 ms
77,144 KB
testcase_14 AC 39 ms
53,448 KB
testcase_15 AC 38 ms
53,368 KB
testcase_16 AC 51 ms
64,240 KB
testcase_17 AC 39 ms
54,296 KB
testcase_18 AC 39 ms
54,736 KB
testcase_19 AC 39 ms
53,936 KB
testcase_20 AC 85 ms
76,532 KB
testcase_21 AC 51 ms
64,304 KB
testcase_22 AC 39 ms
54,136 KB
testcase_23 AC 107 ms
76,932 KB
testcase_24 AC 113 ms
76,872 KB
testcase_25 AC 92 ms
76,480 KB
testcase_26 AC 72 ms
73,244 KB
testcase_27 AC 127 ms
77,360 KB
testcase_28 AC 38 ms
53,752 KB
testcase_29 AC 74 ms
74,492 KB
testcase_30 AC 49 ms
63,684 KB
testcase_31 AC 53 ms
64,532 KB
testcase_32 AC 88 ms
77,092 KB
testcase_33 AC 81 ms
76,592 KB
testcase_34 AC 105 ms
76,932 KB
testcase_35 AC 40 ms
61,164 KB
testcase_36 AC 68 ms
70,892 KB
testcase_37 AC 48 ms
62,780 KB
testcase_38 AC 36 ms
53,224 KB
testcase_39 AC 37 ms
53,884 KB
testcase_40 AC 44 ms
61,072 KB
testcase_41 AC 38 ms
54,716 KB
testcase_42 AC 37 ms
53,688 KB
testcase_43 AC 37 ms
54,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda: sys.stdin.readline().rstrip()

import heapq

def main():
    # 入力
    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()))  # その道の長さ
    # 計算・出力
    edges = [[] for _ in range(N)]  # 辺の情報 [次の街, 通行料, 距離]
    for i in range(V):
        edges[S[i]-1].append([T[i]-1, Y[i], M[i]])
    d = [[10**10]*(C+1) for _ in range(N)]
    # d[i][j] := 街 i に 料金 j でたどり着く最短距離
    d[0][0] = 0
    q = [[0, 0, 0]]  # [総距離, 街, 料金]
    while q:
        prevD, prevV, prevC = heapq.heappop(q)
        if d[prevV][prevC] < prevD: continue
        for nextV, cost, dist in edges[prevV]:
            nextD = prevD + dist
            nextC = prevC + cost
            if nextC <= C and nextD < d[nextV][nextC]:
                d[nextV][nextC] = nextD
                heapq.heappush(q, [nextD, nextV, nextC])
    ans = min(d[-1])
    print(ans if ans < 10**10 else -1)

if __name__ == "__main__":
    main()
0