結果

問題 No.3111 Toll Optimization
ユーザー tkykwtnb
提出日時 2025-04-18 21:51:20
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 742 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 82,724 KB
実行使用メモリ 823,972 KB
最終ジャッジ日時 2025-04-18 21:51:34
合計ジャッジ時間 14,052 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other MLE * 1 -- * 69
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque,defaultdict
N,M,K=map(int,input().split())
C=list(map(int,input().split()))
G=[[] for _ in range(N)]
D=defaultdict(int)
for i in range(M):
    u,v=map(int,input().split())
    u-=1;v-=1
    G[u].append(v)
    G[v].append(u)
    if u>v:u,v=v,u
    D[(u,v)]=C[i]
Q=deque([((0,),(0,))])
cand=[]
while Q:
    route,cost=Q.popleft()
    now=route[-1]
    if now==N-1:
        cand.append(sorted(cost))
        continue
    for nxt in G[now]:
        if nxt in route:continue
        if now>nxt:Q.append((route+(nxt,),cost+(D[(nxt,now)],)))
        else:Q.append((route+(nxt,),cost+(D[(now,nxt)],)))
if len(cand)==0:exit(print(-1))
ans=1<<60
for cost in cand:
    ans=min(ans,sum(cost[:max(1,len(cost)-K)]))
print(ans)
0