結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-06-07 14:59:06 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 94 ms / 5,000 ms |
| コード長 | 682 bytes |
| コンパイル時間 | 339 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2025-06-07 14:59:10 |
| 合計ジャッジ時間 | 3,595 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
INF=10**10
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()))
g=[[] for _ in range(N)]
for i in range(V):
g[S[i]-1].append([T[i]-1,Y[i],M[i]])
from heapq import heappop, heappush, heapify
heap=[(0,C,0)]
heapify(heap)
dp=[[INF for _ in range(C+1)] for _ in range(N)]
dp[0][C]=0
while heap:
mm,cc,u = heappop(heap)
if dp[u][cc]<mm: continue
for v,y,m in g[u]:
if cc-y<0:continue
if dp[v][cc-y]>mm+m:
dp[v][cc-y]=mm+m
heappush(heap,(dp[v][cc-y],cc-y,v))
print(-1 if min(dp[N-1])==INF else min(dp[N-1]))