結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2021-11-01 14:22:07 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 95 ms / 5,000 ms |
| コード長 | 710 bytes |
| コンパイル時間 | 460 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 11,520 KB |
| 最終ジャッジ日時 | 2024-10-10 02:58:34 |
| 合計ジャッジ時間 | 3,540 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
import heapq
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()))
E=[[] for i in range(N+1)]
for i in range(V):
E[S[i]].append((T[i],Y[i],M[i]))
#E[T[i]].append((S[i],Y[i],M[i]))
DP=[[1<<60]*(C+1) for i in range(N+1)]
DP[1][C]=0
Q=[(0,1,C)]
while Q:
now,town,money=heapq.heappop(Q)
if now>DP[town][money]:
continue
for to,y,m in E[town]:
if money-y>=0 and DP[to][money-y]>now+m:
DP[to][money-y]=now+m
heapq.heappush(Q,(now+m,to,money-y))
MIN=min(DP[N])
if MIN==1<<60:
print(-1)
else:
print(MIN)
titia