結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
dn6049949
|
| 提出日時 | 2022-04-15 22:19:50 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 224 ms / 5,000 ms |
| コード長 | 1,197 bytes |
| コンパイル時間 | 601 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 79,104 KB |
| 最終ジャッジ日時 | 2024-12-25 01:10:49 |
| 合計ジャッジ時間 | 6,569 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#!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()
dn6049949