結果
| 問題 |
No.1812 Uribo Road
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-15 22:31:09 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,106 bytes |
| コンパイル時間 | 283 ms |
| コンパイル使用メモリ | 82,104 KB |
| 実行使用メモリ | 81,664 KB |
| 最終ジャッジ日時 | 2024-07-07 09:28:00 |
| 合計ジャッジ時間 | 6,879 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 TLE * 1 |
| other | -- * 30 |
ソースコード
import itertools
import heapq
N,M,K = map(int,input().split())
R = set([i-1 for i in map(int,input().split())])
route = [[] for _ in [0]*N]
edge = [0]*M
st = set([0,N-1])
for i in range(M):
A,B,C = map(int,input().split())
A -= 1; B -= 1
if(i in R):
edge[i] = [A,B,C]
st.add(A); st.add(B)
route[A].append((B,C))
route[B].append((A,C))
def dijkstra(route):
dist = [[-1]*N for _ in [0]*N]
for i in st:
q = [(0,i)]
cnt = 0
while(q and cnt < N):
d,v = heapq.heappop(q)
if(dist[i][v] == -1):
cnt += 1
dist[i][v] = d
for nv,nd in route[v]:
heapq.heappush(q,(d + nd,nv))
return dist
ans = float("inf")
rsum = sum(edge[i][2] for i in R)
dist = dijkstra(route)
for rlist in itertools.permutations(R):
for bit in range(1 << K):
s = rsum
path = [0]
for i in range(K):
if(bit & (1 << i)):
path.append(edge[rlist[i]][0])
path.append(edge[rlist[i]][1])
else:
path.append(edge[rlist[i]][1])
path.append(edge[rlist[i]][0])
path.append(N-1)
for i in range(0,len(path)-1,2):
s += dist[path[i]][path[i+1]]
if(ans > s):
ans = s
print(ans)