結果

問題 No.1 道のショートカット
コンテスト
ユーザー DialBird
提出日時 2019-07-18 21:29:31
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 859 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 107 ms
コンパイル使用メモリ 15,104 KB
実行使用メモリ 300,032 KB
最終ジャッジ日時 2026-10-11 16:33:27
合計ジャッジ時間 9,746 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14 TLE * 1 -- * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from heapq import heappop, heappush


def main():
    """ 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()))

    ways_from = {}
    ways_from = [set() for i in range(N+1)]
    for i in range(V):
        ways_from[S[i]].add((T[i], Y[i], M[i]))

    # time, pos, cost
    heap = [(0, 1, 0)]
    res = -1

    while heap:
        time, pos, cost = heappop(heap)

        if pos == N:
            res = time
            break

        for next_pos, way_cost, way_time in ways_from[pos]:
            next_cost = cost + way_cost
            if C < next_cost:
                continue
            heappush(heap, (time + way_time, next_pos, next_cost))

    return res


print(main())
0