結果

問題 No.1 道のショートカット
ユーザー kjnhokjnho
提出日時 2017-03-22 22:50:42
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 1,229 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 10,972 KB
実行使用メモリ 8,668 KB
最終ジャッジ日時 2023-09-27 22:04:18
合計ジャッジ時間 2,479 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,108 KB
testcase_01 AC 14 ms
8,108 KB
testcase_02 AC 14 ms
8,136 KB
testcase_03 AC 14 ms
8,168 KB
testcase_04 AC 13 ms
8,048 KB
testcase_05 AC 14 ms
8,100 KB
testcase_06 AC 13 ms
8,244 KB
testcase_07 AC 13 ms
8,064 KB
testcase_08 AC 15 ms
8,100 KB
testcase_09 AC 14 ms
8,112 KB
testcase_10 AC 14 ms
8,136 KB
testcase_11 AC 15 ms
8,092 KB
testcase_12 AC 15 ms
8,640 KB
testcase_13 AC 15 ms
8,524 KB
testcase_14 AC 13 ms
8,384 KB
testcase_15 AC 13 ms
8,132 KB
testcase_16 AC 15 ms
8,048 KB
testcase_17 AC 14 ms
8,048 KB
testcase_18 AC 15 ms
8,448 KB
testcase_19 AC 14 ms
8,252 KB
testcase_20 AC 14 ms
8,128 KB
testcase_21 AC 14 ms
8,404 KB
testcase_22 AC 14 ms
8,364 KB
testcase_23 AC 15 ms
8,668 KB
testcase_24 AC 15 ms
8,028 KB
testcase_25 AC 13 ms
8,024 KB
testcase_26 AC 14 ms
8,024 KB
testcase_27 AC 14 ms
8,096 KB
testcase_28 AC 14 ms
8,084 KB
testcase_29 AC 15 ms
8,148 KB
testcase_30 AC 14 ms
8,140 KB
testcase_31 AC 14 ms
8,144 KB
testcase_32 AC 14 ms
8,200 KB
testcase_33 AC 14 ms
8,176 KB
testcase_34 AC 15 ms
8,496 KB
testcase_35 AC 14 ms
8,648 KB
testcase_36 AC 15 ms
8,196 KB
testcase_37 AC 15 ms
8,044 KB
testcase_38 AC 14 ms
8,312 KB
testcase_39 AC 13 ms
8,276 KB
testcase_40 AC 13 ms
8,080 KB
testcase_41 AC 13 ms
8,280 KB
testcase_42 AC 13 ms
8,080 KB
testcase_43 AC 13 ms
8,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush, heapify


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()))  # money
    M = list(map(int, input().split()))  # time

    MAP = [[] for n in range(N)]

    for v in range(V):
        MAP[S[v]-1].append((M[v], Y[v], T[v]-1))

    m_cost = 0
    t_cost = 0
    Q = [(0, 0, 0)]  # time_cost, money_cost, point
    tcosts = [float("inf")] * N  # time cost map
    mcosts = [float("inf")] * N  # time cost map
    R = [False] * N  # reached

    while len(Q) > 0:
        t_cost, m_cost, point = heappop(Q)
        if point == N-1:
            print(t_cost)
            return

        for n in MAP[point]:
            new_tcost = t_cost + n[0]
            new_mcost = m_cost + n[1]
            new_point = n[2]
            if m_cost + n[1] > C:
                continue
            if new_tcost < tcosts[new_point] or new_mcost < mcosts[new_point]:
                heappush(Q, (new_tcost, new_mcost, new_point))
                tcosts[point] = new_tcost
                mcosts[point] = new_mcost

    print(-1)


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