結果
問題 | No.1 道のショートカット |
ユーザー |
![]() |
提出日時 | 2019-12-26 18:21:36 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 34 ms / 5,000 ms |
コード長 | 1,059 bytes |
コンパイル時間 | 205 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-07-20 16:44:50 |
合計ジャッジ時間 | 2,642 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
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()