結果
| 問題 |
No.3111 Toll Optimization
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-18 21:56:39 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 685 bytes |
| コンパイル時間 | 287 ms |
| コンパイル使用メモリ | 82,000 KB |
| 実行使用メモリ | 126,532 KB |
| 最終ジャッジ日時 | 2025-04-18 21:56:50 |
| 合計ジャッジ時間 | 9,947 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | RE * 5 TLE * 1 -- * 64 |
ソースコード
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]
def dfs(route,cost):
global ans
now=route[-1]
if now==N-1:
cost=sorted(cost)
ans=min(ans,sum(cost[:max(1,len(cost)-K)]))
return
for nxt in G[now]:
if nxt in route:continue
if now>nxt:dfs(route+(nxt,),cost+(D[(nxt,now)],))
else:dfs(route+(nxt,),cost+(D[(now,nxt)],))
ans=1<<60
dfs((0,),(0,))
if ans<1<<60:print(ans)
else:print(-1)