結果

問題 No.1814 Uribo Road (Easy)
ユーザー MasKoaTSMasKoaTS
提出日時 2021-11-05 11:34:46
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,052 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 265,496 KB
最終ジャッジ日時 2024-05-01 17:32:36
合計ジャッジ時間 26,752 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,992 KB
testcase_01 AC 55 ms
65,280 KB
testcase_02 AC 38 ms
53,120 KB
testcase_03 AC 37 ms
52,992 KB
testcase_04 AC 37 ms
52,480 KB
testcase_05 AC 37 ms
52,992 KB
testcase_06 AC 47 ms
60,928 KB
testcase_07 AC 37 ms
52,864 KB
testcase_08 AC 38 ms
52,608 KB
testcase_09 AC 126 ms
77,440 KB
testcase_10 AC 122 ms
76,672 KB
testcase_11 AC 186 ms
78,336 KB
testcase_12 AC 239 ms
81,280 KB
testcase_13 AC 193 ms
79,104 KB
testcase_14 AC 276 ms
83,968 KB
testcase_15 AC 135 ms
77,056 KB
testcase_16 AC 154 ms
77,636 KB
testcase_17 AC 227 ms
78,580 KB
testcase_18 AC 134 ms
77,312 KB
testcase_19 AC 137 ms
77,440 KB
testcase_20 AC 714 ms
125,668 KB
testcase_21 AC 309 ms
80,056 KB
testcase_22 AC 1,388 ms
246,016 KB
testcase_23 AC 896 ms
146,304 KB
testcase_24 AC 1,305 ms
229,888 KB
testcase_25 AC 1,317 ms
228,480 KB
testcase_26 AC 1,699 ms
265,496 KB
testcase_27 AC 1,857 ms
264,320 KB
testcase_28 AC 1,990 ms
263,552 KB
testcase_29 TLE -
testcase_30 AC 1,628 ms
263,808 KB
testcase_31 AC 1,638 ms
263,808 KB
testcase_32 AC 241 ms
80,628 KB
testcase_33 AC 142 ms
77,056 KB
testcase_34 AC 122 ms
76,928 KB
testcase_35 AC 321 ms
86,340 KB
testcase_36 AC 174 ms
77,568 KB
testcase_37 AC 244 ms
80,532 KB
testcase_38 AC 375 ms
89,500 KB
testcase_39 AC 183 ms
78,592 KB
testcase_40 AC 218 ms
80,272 KB
testcase_41 AC 1,530 ms
263,384 KB
testcase_42 AC 551 ms
108,180 KB
testcase_43 AC 211 ms
79,248 KB
testcase_44 AC 394 ms
96,384 KB
testcase_45 AC 167 ms
78,004 KB
testcase_46 AC 1,414 ms
247,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
import heapq

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

route = [[] for _ in [0]*N]
edge = [0]*M
for i in range(M):
	A,B,C = map(int,input().split())
	A -= 1;	B -= 1
	edge[i] = [A,B,C]
	route[A].append((B,C))
	route[B].append((A,C))

def dijkstra(route):
	dist = [[-1]*N for _ in [0]*N]
	for i in range(N):
		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