結果

問題 No.1 道のショートカット
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-05-27 19:31:49
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 1,371 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 9,280 KB
最終ジャッジ日時 2023-09-27 21:56:21
合計ジャッジ時間 2,226 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,716 KB
testcase_01 AC 18 ms
8,716 KB
testcase_02 AC 17 ms
8,596 KB
testcase_03 AC 17 ms
8,724 KB
testcase_04 AC 16 ms
8,676 KB
testcase_05 AC 17 ms
8,672 KB
testcase_06 AC 16 ms
8,732 KB
testcase_07 AC 16 ms
8,632 KB
testcase_08 AC 20 ms
9,140 KB
testcase_09 AC 18 ms
9,112 KB
testcase_10 AC 18 ms
9,184 KB
testcase_11 AC 19 ms
9,112 KB
testcase_12 AC 19 ms
9,244 KB
testcase_13 AC 21 ms
9,280 KB
testcase_14 AC 17 ms
8,600 KB
testcase_15 AC 17 ms
8,724 KB
testcase_16 AC 17 ms
8,724 KB
testcase_17 AC 16 ms
8,572 KB
testcase_18 AC 16 ms
8,684 KB
testcase_19 AC 17 ms
8,620 KB
testcase_20 AC 17 ms
8,668 KB
testcase_21 AC 16 ms
8,788 KB
testcase_22 AC 17 ms
8,588 KB
testcase_23 AC 21 ms
9,244 KB
testcase_24 AC 20 ms
9,124 KB
testcase_25 AC 18 ms
8,664 KB
testcase_26 AC 17 ms
8,776 KB
testcase_27 AC 20 ms
9,100 KB
testcase_28 AC 16 ms
8,644 KB
testcase_29 AC 21 ms
9,252 KB
testcase_30 AC 17 ms
8,792 KB
testcase_31 AC 18 ms
8,796 KB
testcase_32 AC 19 ms
8,980 KB
testcase_33 AC 18 ms
8,876 KB
testcase_34 AC 20 ms
9,116 KB
testcase_35 AC 19 ms
8,916 KB
testcase_36 AC 18 ms
9,080 KB
testcase_37 AC 18 ms
8,900 KB
testcase_38 AC 16 ms
8,672 KB
testcase_39 AC 17 ms
8,720 KB
testcase_40 AC 17 ms
8,760 KB
testcase_41 AC 17 ms
8,692 KB
testcase_42 AC 16 ms
8,780 KB
testcase_43 AC 16 ms
8,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import collections
import heapq


IMPOSSIBLE = -1
Edge = collections.namedtuple("Edge", "start end money time")
AdjVertex = collections.namedtuple("AdjVertex", "dest, money, time")
State = collections.namedtuple("State", "time money vertex")


def compute_min_time(num_vertices, money_limit, adj_vertices):
    pq = []
    heapq.heappush(pq, State(0, 0, 0))
    while pq:
        state0 = heapq.heappop(pq)
        if state0.vertex == num_vertices - 1:
            return state0.time
        for v in adj_vertices[state0.vertex]:
            new_money = state0.money + v.money
            if new_money <= money_limit:
                new_time = state0.time + v.time
                heapq.heappush(pq, State(new_time, new_money, v.dest))
    else:
        return IMPOSSIBLE


def main():
    num_vertices = int(input())
    money_limit = int(input())
    _ = input()
    ss = map(lambda x: int(x) - 1, input().split())
    ts = map(lambda x: int(x) - 1, input().split())
    ys = map(int, input().split())
    ms = map(int, input().split())
    adj_vertices = [set() for _ in range(num_vertices)]
    for edge in (Edge(*args) for args in zip(ss, ts, ys, ms)):
        adj_vertices[edge.start].add(AdjVertex(*edge[1:]))
    answer = compute_min_time(num_vertices, money_limit, adj_vertices)
    print(answer)


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