結果

問題 No.1812 Uribo Road
ユーザー MasKoaTSMasKoaTS
提出日時 2021-12-06 15:49:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,354 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 11,032 KB
実行使用メモリ 15,660 KB
最終ジャッジ日時 2023-09-21 15:44:14
合計ジャッジ時間 6,820 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,552 KB
testcase_01 AC 19 ms
8,584 KB
testcase_02 AC 79 ms
8,416 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 itertools
import heapq
import sys
input = sys.stdin.readline
INF = 10 ** 18

N,M,K = map(int,input().split())
R = set([i - 1 for i in map(int,input().split())])
lR = list(R)

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

ans = INF
rsum = sum(edge[i][2] for i in R)
dist = [[] for _ in [0]*N]
for i in st:
    dist[i] = dijkstra(i,route)

for rbit in range(1 << K):
	b = [(rbit >> i) & 1 for i in range(K)]

	dp = [[INF]*K for i in range(1 << K)]
	for i in range(K):
		p = edge[lR[i]][b[i]]
		dp[1 << i][i] = dist[0][p] + rsum
	
	for bit in range(1, 1 << K):
		for s in range(K):
			p = edge[lR[s]][b[s]^1]
			if not(bit & (1 << s)):
				continue
			for t in range(K):
				np = edge[lR[t]][b[t]]
				k = bit | (1 << t)
				d = dp[bit][s] + dist[p][np]
				if((bit & (1 << t)) == 0 and dp[k][t] > d):
					dp[k][t] = d

	c = INF
	for i in range(K):
		p = edge[lR[i]][b[i]^1]
		d = dp[-1][i] + dist[p][N-1]
		if(c > d):
			c = d

	if(ans > c):
		ans = c

print(ans)
0