結果
| 問題 |
No.3111 Toll Optimization
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2025-04-19 01:15:22 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,842 ms / 5,000 ms |
| コード長 | 862 bytes |
| コンパイル時間 | 1,188 ms |
| コンパイル使用メモリ | 82,384 KB |
| 実行使用メモリ | 133,452 KB |
| 最終ジャッジ日時 | 2025-04-19 01:16:06 |
| 合計ジャッジ時間 | 38,665 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 70 |
ソースコード
import sys
input = sys.stdin.readline
from heapq import heappop,heappush
N,M,K=map(int,input().split())
C=list(map(int,input().split()))
E=[[] for i in range(N)]
for i in range(M):
x,y=map(int,input().split())
x-=1
y-=1
E[x].append((y,C[i]))
E[y].append((x,C[i]))
DP=[[1<<63]*N for i in range(K+1)]
DP[0][0]=0
Q=[(0,0,0)]
while Q:
time,town,coupon=heappop(Q)
if DP[coupon][town]!=time:
continue
for to,dis in E[town]:
if DP[coupon][to]>time+dis:
DP[coupon][to]=time+dis
heappush(Q,(DP[coupon][to],to,coupon))
if coupon+1<=K:
if DP[coupon+1][to]>time:
DP[coupon+1][to]=time
heappush(Q,(DP[coupon+1][to],to,coupon+1))
ANS=1<<63
for i in range(K+1):
ANS=min(ANS,DP[i][N-1])
if ANS>1<<62:
print(-1)
else:
print(ANS)
titia