結果
問題 | No.1 道のショートカット |
ユーザー |
![]() |
提出日時 | 2021-01-02 05:31:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 144 ms / 5,000 ms |
コード長 | 894 bytes |
コンパイル時間 | 388 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 77,440 KB |
最終ジャッジ日時 | 2024-10-11 19:23:25 |
合計ジャッジ時間 | 5,001 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
import heapq import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) N = int(input()) C = int(input()) V = int(input()) S = list(map(int, input().split())) T = list(map(int, input().split())) Y = list(map(int, input().split())) M = list(map(int, input().split())) edge = [[] for _ in range(N)] for s, t, y, m in zip(S, T, Y, M): edge[s-1].append((t-1, y, m)) inf = 10**18 dist = [[inf] * (C + 1) for _ in range(N)] dist[0][0] = 0 que = [(0, 0, 0)] # time, cost, pos while que: ds, cs, s = heapq.heappop(que) if dist[s][cs] < ds: continue for t, ct, dt in edge[s]: if ct + cs > C: continue if dist[t][ct + cs] > ds + dt: dist[t][ct + cs] = ds + dt heapq.heappush(que, (ds + dt, ct + cs, t)) ans = inf for i in range(C + 1): ans = min(ans, dist[N-1][i]) if ans >= inf: ans = -1 print(ans)