結果

問題 No.1 道のショートカット
ユーザー mkawa2mkawa2
提出日時 2019-12-26 18:21:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 1,059 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 9,020 KB
最終ジャッジ日時 2023-09-27 22:24:54
合計ジャッジ時間 2,484 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,644 KB
testcase_01 AC 19 ms
8,624 KB
testcase_02 AC 18 ms
8,756 KB
testcase_03 AC 17 ms
8,632 KB
testcase_04 AC 17 ms
8,612 KB
testcase_05 AC 17 ms
8,568 KB
testcase_06 AC 16 ms
8,620 KB
testcase_07 AC 17 ms
8,668 KB
testcase_08 AC 19 ms
8,864 KB
testcase_09 AC 19 ms
8,732 KB
testcase_10 AC 19 ms
8,872 KB
testcase_11 AC 19 ms
8,976 KB
testcase_12 AC 21 ms
9,020 KB
testcase_13 AC 20 ms
8,920 KB
testcase_14 AC 18 ms
8,716 KB
testcase_15 AC 18 ms
8,804 KB
testcase_16 AC 18 ms
8,664 KB
testcase_17 AC 17 ms
8,704 KB
testcase_18 AC 17 ms
8,712 KB
testcase_19 AC 16 ms
8,584 KB
testcase_20 AC 17 ms
8,656 KB
testcase_21 AC 17 ms
8,636 KB
testcase_22 AC 17 ms
8,820 KB
testcase_23 AC 20 ms
8,944 KB
testcase_24 AC 19 ms
8,896 KB
testcase_25 AC 17 ms
8,788 KB
testcase_26 AC 18 ms
8,668 KB
testcase_27 AC 19 ms
8,844 KB
testcase_28 AC 17 ms
8,736 KB
testcase_29 AC 20 ms
8,900 KB
testcase_30 AC 17 ms
8,672 KB
testcase_31 AC 18 ms
8,924 KB
testcase_32 AC 18 ms
8,916 KB
testcase_33 AC 18 ms
8,732 KB
testcase_34 AC 21 ms
8,884 KB
testcase_35 AC 21 ms
8,900 KB
testcase_36 AC 19 ms
8,788 KB
testcase_37 AC 19 ms
8,792 KB
testcase_38 AC 18 ms
8,632 KB
testcase_39 AC 18 ms
8,720 KB
testcase_40 AC 19 ms
8,660 KB
testcase_41 AC 17 ms
8,716 KB
testcase_42 AC 16 ms
8,640 KB
testcase_43 AC 18 ms
8,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
from collections import defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n = II()
    inf=1000
    money = II()
    m = II()
    uu = LI1()
    vv = LI1()
    cc = LI()
    tt = LI()
    to = defaultdict(list)
    for u, v, c, t in zip(uu, vv, cc, tt):
        to[u].append([v, c, t])
    hp=[]
    costs=[inf]*n
    #[時間,都市,コスト]
    heappush(hp,[0,0,0])
    while hp:
        time,u,cost=heappop(hp)
        if u==n-1:
            print(time)
            exit()
        if cost>costs[u]:continue
        costs[u]=cost
        for v,c,t in to[u]:
            if cost+c>money:continue
            heappush(hp,[time+t,v,cost+c])
    print(-1)

main()
0