結果

問題 No.1 道のショートカット
ユーザー dn6049949dn6049949
提出日時 2022-04-15 22:19:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 223 ms / 5,000 ms
コード長 1,197 bytes
コンパイル時間 420 ms
コンパイル使用メモリ 87,348 KB
実行使用メモリ 80,328 KB
最終ジャッジ日時 2023-08-26 08:10:47
合計ジャッジ時間 8,516 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,716 KB
testcase_01 AC 99 ms
71,684 KB
testcase_02 AC 99 ms
71,348 KB
testcase_03 AC 96 ms
71,480 KB
testcase_04 AC 96 ms
71,424 KB
testcase_05 AC 96 ms
71,748 KB
testcase_06 AC 94 ms
71,516 KB
testcase_07 AC 93 ms
71,364 KB
testcase_08 AC 159 ms
78,852 KB
testcase_09 AC 122 ms
77,872 KB
testcase_10 AC 156 ms
79,148 KB
testcase_11 AC 187 ms
79,500 KB
testcase_12 AC 213 ms
79,976 KB
testcase_13 AC 204 ms
80,204 KB
testcase_14 AC 97 ms
71,668 KB
testcase_15 AC 97 ms
71,592 KB
testcase_16 AC 113 ms
77,960 KB
testcase_17 AC 94 ms
71,516 KB
testcase_18 AC 98 ms
72,444 KB
testcase_19 AC 96 ms
72,188 KB
testcase_20 AC 143 ms
78,616 KB
testcase_21 AC 115 ms
77,760 KB
testcase_22 AC 99 ms
72,380 KB
testcase_23 AC 187 ms
79,532 KB
testcase_24 AC 195 ms
79,932 KB
testcase_25 AC 161 ms
79,160 KB
testcase_26 AC 138 ms
78,404 KB
testcase_27 AC 223 ms
80,328 KB
testcase_28 AC 96 ms
71,880 KB
testcase_29 AC 135 ms
77,912 KB
testcase_30 AC 107 ms
77,680 KB
testcase_31 AC 114 ms
77,708 KB
testcase_32 AC 171 ms
79,016 KB
testcase_33 AC 147 ms
78,660 KB
testcase_34 AC 199 ms
79,600 KB
testcase_35 AC 101 ms
76,836 KB
testcase_36 AC 124 ms
77,840 KB
testcase_37 AC 103 ms
77,308 KB
testcase_38 AC 94 ms
71,712 KB
testcase_39 AC 98 ms
72,180 KB
testcase_40 AC 103 ms
77,056 KB
testcase_41 AC 94 ms
71,392 KB
testcase_42 AC 95 ms
71,804 KB
testcase_43 AC 93 ms
71,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def IR(n):
    return [I() for _ in range(n)]
def LIR(n):
    return [LI() for _ in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def main():
    n = I()
    x = I()
    I()
    s = LI()
    t = LI()
    y = LI()
    m = LI()
    v = [[] for _ in range(n)]
    for a,b,c,d in zip(s,t,y,m):
        a -= 1
        b -= 1
        v[a].append((b,c,d))
    d = defaultdict(lambda : float("inf"))
    d[(0,x)] = 0
    q = [(0,0,x)]
    ans = float("inf")
    while q:
        dx,x,c = heappop(q)
        if dx > d[(x,c)]:
            continue
        if x == n-1 and dx < ans:
            ans = dx
        for y,cost,w in v[x]:
            nd = dx+w
            nc = c-cost
            if nc >= 0 and nd < d[(y,nc)]:
                d[(y,nc)] = nd
                heappush(q,(nd,y,nc))
    if ans == float("inf"):
        ans = -1
    print(ans)
    return


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