結果

問題 No.1812 Uribo Road
ユーザー MasKoaTSMasKoaTS
提出日時 2021-12-22 13:35:55
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,352 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 131,800 KB
最終ジャッジ日時 2023-10-14 13:04:51
合計ジャッジ時間 9,249 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
71,508 KB
testcase_01 AC 81 ms
71,052 KB
testcase_02 AC 110 ms
76,460 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq as hq
import sys
input = sys.stdin.readline
INF = 10 ** 18

N,M,K = map(int, input().split())
R = [i - 1 for i in map(int, input().split())]
S = set(R)
edge = [[] for _ in [0] * M]
route = [[] for _ in [0] * N]
rsum = 0
for i in range(M):
	a,b,c = map(int, input().split())
	a -= 1;	b -= 1
	route[a].append((b,c))
	route[b].append((a,c))
	if(i in S):
		edge[i] = [a,b,c]
		rsum += c

def dijkstra(s,route):
	que = [(s,0)]
	dist = [INF] * N
	while(que):
		v,d = hq.heappop(que)
		if(dist[v] < INF):
			continue
		dist[v] = d
		for nv,nd in route[v]:
			hq.heappush(que,(nv,d + nd))
	return dist

dist = [[] for _ in [0] * N]
T = set([0,N - 1])
for i in S:
	T.add(edge[i][0])
	T.add(edge[i][1])
for i in T:
	dist[i] = dijkstra(i,route)

ans = INF
for rbit in range(1 << K):
	b = [(rbit >> i) & 1 for i in range(K)]
	dp = [[INF] * K for _ in [0] * (1 << K)]
	for i in range(K):
		k = edge[R[i]][b[i]]
		dp[1 << i][i] = rsum + dist[0][k]
	for bit in range(1, 1 << K):
		for s in range(K):
			if not(bit & (1 << s)):
				continue
			k = edge[R[s]][b[s] ^ 1]
			for t in range(K):
				l = edge[R[t]][b[t]]
				p = bit | (1 << t)
				q = dp[bit][s] + dist[k][l]
				if((bit & (1 << t)) == 0 and dp[p][t] > q):
					dp[p][t] = q
	for i in range(K):
		k = edge[R[i]][b[i] ^ 1]
		d = dp[-1][i] + dist[k][N - 1]
		if(ans > d):
			ans = d

print(ans)
0