結果

問題 No.1812 Uribo Road
ユーザー MasKoaTSMasKoaTS
提出日時 2021-12-31 15:10:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,038 ms / 5,000 ms
コード長 1,390 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 117,632 KB
最終ジャッジ日時 2024-04-17 03:04:14
合計ジャッジ時間 12,884 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
52,736 KB
testcase_01 AC 40 ms
52,736 KB
testcase_02 AC 54 ms
63,232 KB
testcase_03 AC 122 ms
81,024 KB
testcase_04 AC 40 ms
52,992 KB
testcase_05 AC 40 ms
53,376 KB
testcase_06 AC 43 ms
53,376 KB
testcase_07 AC 83 ms
74,496 KB
testcase_08 AC 134 ms
76,928 KB
testcase_09 AC 153 ms
77,568 KB
testcase_10 AC 123 ms
77,056 KB
testcase_11 AC 131 ms
77,184 KB
testcase_12 AC 461 ms
87,060 KB
testcase_13 AC 245 ms
86,016 KB
testcase_14 AC 246 ms
85,888 KB
testcase_15 AC 669 ms
97,628 KB
testcase_16 AC 347 ms
80,976 KB
testcase_17 AC 887 ms
101,928 KB
testcase_18 AC 884 ms
117,632 KB
testcase_19 AC 1,028 ms
107,684 KB
testcase_20 AC 1,038 ms
108,644 KB
testcase_21 AC 939 ms
109,572 KB
testcase_22 AC 907 ms
110,916 KB
testcase_23 AC 151 ms
77,992 KB
testcase_24 AC 70 ms
68,608 KB
testcase_25 AC 226 ms
81,168 KB
testcase_26 AC 151 ms
77,696 KB
testcase_27 AC 734 ms
105,600 KB
testcase_28 AC 310 ms
83,292 KB
testcase_29 AC 41 ms
53,248 KB
testcase_30 AC 208 ms
79,112 KB
testcase_31 AC 628 ms
96,536 KB
testcase_32 AC 140 ms
77,184 KB
testcase_33 AC 330 ms
88,292 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]
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]

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] = dist[0][edge[R[i]][j ^ 1]] + edge[R[i]][2]
for bit in range(1, 1 << K):
	for s in range(K):
		if not(bit & (1 << s)):
			continue
		for t in range(K):
			if(bit & (1 << t)):
				continue
			b = bit | (1 << t);	c = edge[R[t]][2]
			for x in range(2):
				for y in range(2):
					p = edge[R[s]][x];	q = edge[R[t]][y ^ 1]
					d = dp[bit][s][x] + dist[p][q] + c
					if(dp[b][t][y] > d):
						dp[b][t][y] = d

ans = INF
for i in range(K):
	for j in range(2):
		d = dp[-1][i][j] + dist[edge[R[i]][j]][N - 1]
		if(ans > d):
			ans = d
print(ans)
0