結果

問題 No.1 道のショートカット
ユーザー kjnho
提出日時 2017-03-22 22:50:42
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 33 ms / 5,000 ms
コード長 1,229 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-07-20 16:29:06
合計ジャッジ時間 2,334 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

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