結果

問題 No.1 道のショートカット
ユーザー mkawa2mkawa2
提出日時 2019-12-26 18:14:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,091 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 11,016 KB
実行使用メモリ 9,352 KB
最終ジャッジ日時 2023-09-22 13:39:20
合計ジャッジ時間 2,487 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,728 KB
testcase_01 AC 19 ms
8,600 KB
testcase_02 AC 19 ms
8,712 KB
testcase_03 AC 19 ms
8,608 KB
testcase_04 AC 19 ms
8,532 KB
testcase_05 AC 19 ms
8,728 KB
testcase_06 AC 19 ms
8,744 KB
testcase_07 AC 19 ms
8,692 KB
testcase_08 AC 21 ms
8,948 KB
testcase_09 AC 21 ms
8,992 KB
testcase_10 AC 21 ms
8,908 KB
testcase_11 AC 21 ms
9,048 KB
testcase_12 AC 22 ms
9,160 KB
testcase_13 AC 22 ms
9,148 KB
testcase_14 AC 19 ms
8,560 KB
testcase_15 AC 19 ms
8,680 KB
testcase_16 WA -
testcase_17 AC 19 ms
8,608 KB
testcase_18 AC 19 ms
8,612 KB
testcase_19 AC 20 ms
8,688 KB
testcase_20 AC 19 ms
8,644 KB
testcase_21 WA -
testcase_22 AC 19 ms
8,800 KB
testcase_23 AC 23 ms
9,352 KB
testcase_24 AC 22 ms
9,044 KB
testcase_25 AC 19 ms
8,680 KB
testcase_26 AC 19 ms
8,784 KB
testcase_27 AC 22 ms
9,240 KB
testcase_28 AC 19 ms
8,680 KB
testcase_29 AC 22 ms
8,948 KB
testcase_30 AC 19 ms
8,788 KB
testcase_31 AC 21 ms
8,984 KB
testcase_32 AC 21 ms
8,948 KB
testcase_33 AC 20 ms
8,936 KB
testcase_34 AC 22 ms
9,156 KB
testcase_35 AC 21 ms
9,108 KB
testcase_36 AC 21 ms
9,012 KB
testcase_37 WA -
testcase_38 AC 19 ms
8,756 KB
testcase_39 WA -
testcase_40 AC 20 ms
8,808 KB
testcase_41 AC 19 ms
8,772 KB
testcase_42 AC 19 ms
8,664 KB
testcase_43 AC 20 ms
8,668 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])
        to[v].append([u, 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