結果

問題 No.1814 Uribo Road (Easy)
ユーザー MasKoaTSMasKoaTS
提出日時 2021-11-05 15:11:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 290 ms / 2,000 ms
コード長 1,106 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 97,280 KB
最終ジャッジ日時 2024-05-01 17:31:36
合計ジャッジ時間 7,908 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,608 KB
testcase_01 AC 52 ms
65,664 KB
testcase_02 AC 38 ms
53,120 KB
testcase_03 AC 39 ms
53,248 KB
testcase_04 AC 39 ms
52,480 KB
testcase_05 AC 43 ms
53,248 KB
testcase_06 AC 47 ms
61,184 KB
testcase_07 AC 38 ms
52,608 KB
testcase_08 AC 38 ms
53,376 KB
testcase_09 AC 99 ms
77,184 KB
testcase_10 AC 82 ms
76,032 KB
testcase_11 AC 105 ms
77,440 KB
testcase_12 AC 138 ms
78,140 KB
testcase_13 AC 131 ms
78,096 KB
testcase_14 AC 155 ms
78,464 KB
testcase_15 AC 96 ms
77,056 KB
testcase_16 AC 115 ms
77,684 KB
testcase_17 AC 122 ms
78,008 KB
testcase_18 AC 94 ms
76,928 KB
testcase_19 AC 90 ms
76,752 KB
testcase_20 AC 166 ms
80,064 KB
testcase_21 AC 142 ms
77,876 KB
testcase_22 AC 188 ms
86,260 KB
testcase_23 AC 171 ms
81,152 KB
testcase_24 AC 216 ms
88,704 KB
testcase_25 AC 220 ms
88,288 KB
testcase_26 AC 252 ms
92,728 KB
testcase_27 AC 274 ms
97,000 KB
testcase_28 AC 284 ms
97,120 KB
testcase_29 AC 290 ms
97,280 KB
testcase_30 AC 236 ms
95,812 KB
testcase_31 AC 228 ms
94,604 KB
testcase_32 AC 151 ms
78,216 KB
testcase_33 AC 90 ms
76,544 KB
testcase_34 AC 79 ms
76,288 KB
testcase_35 AC 135 ms
77,952 KB
testcase_36 AC 119 ms
77,184 KB
testcase_37 AC 114 ms
77,764 KB
testcase_38 AC 170 ms
79,452 KB
testcase_39 AC 133 ms
77,440 KB
testcase_40 AC 137 ms
77,768 KB
testcase_41 AC 167 ms
84,360 KB
testcase_42 AC 144 ms
78,964 KB
testcase_43 AC 137 ms
77,696 KB
testcase_44 AC 171 ms
80,688 KB
testcase_45 AC 123 ms
77,732 KB
testcase_46 AC 211 ms
87,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0