結果
問題 | No.1 道のショートカット |
ユーザー |
![]() |
提出日時 | 2020-06-12 00:56:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 227 ms / 5,000 ms |
コード長 | 766 bytes |
コンパイル時間 | 232 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 81,408 KB |
最終ジャッジ日時 | 2024-07-20 16:49:33 |
合計ジャッジ時間 | 4,927 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
from heapq import heapify, heappop, heappush N = int(input()) C = int(input()) V = int(input()) *S, = map(int, input().split()) *T, = map(int, input().split()) *Y, = map(int, input().split()) *M, = map(int, input().split()) G = [[] for _ in [0]*(N+1)] for s, *t in zip(S, T, Y, M): G[s].append(t) INF = 10**10 D = [[INF]*(C+1) for _ in [0]*(N+1)] used = set() q = [] heappush(q, (0, 1, C)) while q: dmin = INF d, v, c = heappop(q) if (v, c) in used: continue used.add((v, c)) D[v][c] = d for u, y, m in G[v]: if (u, c-y) in used or c-y < 0: continue new_d = d+m if new_d < D[u][c-y]: heappush(q, (d+m, u, c-y)) ans = min(D[N]) if ans == INF: print(-1) else: print(ans)