結果

問題 No.1812 Uribo Road
ユーザー MasKoaTSMasKoaTS
提出日時 2021-12-30 00:02:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,311 ms / 5,000 ms
コード長 1,382 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 118,040 KB
最終ジャッジ日時 2024-04-16 08:56:41
合計ジャッジ時間 15,619 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,608 KB
testcase_01 AC 46 ms
53,376 KB
testcase_02 AC 59 ms
63,360 KB
testcase_03 AC 143 ms
81,152 KB
testcase_04 AC 44 ms
52,480 KB
testcase_05 AC 45 ms
52,992 KB
testcase_06 AC 44 ms
53,632 KB
testcase_07 AC 78 ms
72,320 KB
testcase_08 AC 148 ms
76,676 KB
testcase_09 AC 170 ms
77,568 KB
testcase_10 AC 136 ms
77,060 KB
testcase_11 AC 143 ms
76,928 KB
testcase_12 AC 623 ms
86,648 KB
testcase_13 AC 277 ms
86,016 KB
testcase_14 AC 280 ms
86,016 KB
testcase_15 AC 796 ms
98,104 KB
testcase_16 AC 471 ms
82,060 KB
testcase_17 AC 1,115 ms
102,036 KB
testcase_18 AC 1,083 ms
118,040 KB
testcase_19 AC 1,301 ms
108,320 KB
testcase_20 AC 1,311 ms
108,780 KB
testcase_21 AC 1,184 ms
109,572 KB
testcase_22 AC 1,170 ms
110,760 KB
testcase_23 AC 167 ms
78,256 KB
testcase_24 AC 70 ms
68,864 KB
testcase_25 AC 275 ms
81,600 KB
testcase_26 AC 158 ms
77,368 KB
testcase_27 AC 873 ms
105,976 KB
testcase_28 AC 367 ms
84,052 KB
testcase_29 AC 46 ms
53,376 KB
testcase_30 AC 236 ms
79,244 KB
testcase_31 AC 804 ms
97,052 KB
testcase_32 AC 147 ms
76,800 KB
testcase_33 AC 393 ms
88,012 KB
権限があれば一括ダウンロードができます

ソースコード

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 = [(0,s)]
	dist = [INF] * N
	while(que):
		d,v = hq.heappop(que)
		if(dist[v] < INF):
			continue
		dist[v] = d
		for nv,nd in route[v]:
			hq.heappush(que,(d + nd, nv))
	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)

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