結果

問題 No.1814 Uribo Road (Easy)
ユーザー MasKoaTSMasKoaTS
提出日時 2021-10-16 13:40:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 402 ms / 2,000 ms
コード長 988 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 80,768 KB
最終ジャッジ日時 2024-05-01 17:26:05
合計ジャッジ時間 9,454 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,224 KB
testcase_01 AC 77 ms
71,040 KB
testcase_02 AC 43 ms
52,224 KB
testcase_03 AC 43 ms
51,968 KB
testcase_04 AC 43 ms
52,224 KB
testcase_05 AC 44 ms
52,736 KB
testcase_06 AC 58 ms
61,568 KB
testcase_07 AC 43 ms
52,224 KB
testcase_08 AC 43 ms
52,224 KB
testcase_09 AC 93 ms
76,416 KB
testcase_10 AC 66 ms
63,360 KB
testcase_11 AC 93 ms
73,472 KB
testcase_12 AC 110 ms
76,928 KB
testcase_13 AC 110 ms
76,672 KB
testcase_14 AC 156 ms
77,568 KB
testcase_15 AC 172 ms
76,672 KB
testcase_16 AC 183 ms
76,672 KB
testcase_17 AC 200 ms
77,184 KB
testcase_18 AC 223 ms
77,056 KB
testcase_19 AC 220 ms
76,928 KB
testcase_20 AC 344 ms
78,080 KB
testcase_21 AC 362 ms
77,616 KB
testcase_22 AC 279 ms
80,000 KB
testcase_23 AC 402 ms
78,464 KB
testcase_24 AC 235 ms
78,336 KB
testcase_25 AC 233 ms
78,720 KB
testcase_26 AC 259 ms
80,256 KB
testcase_27 AC 201 ms
80,512 KB
testcase_28 AC 272 ms
80,384 KB
testcase_29 AC 204 ms
80,768 KB
testcase_30 AC 196 ms
80,256 KB
testcase_31 AC 193 ms
80,384 KB
testcase_32 AC 124 ms
77,260 KB
testcase_33 AC 68 ms
64,640 KB
testcase_34 AC 60 ms
62,592 KB
testcase_35 AC 119 ms
77,184 KB
testcase_36 AC 106 ms
76,928 KB
testcase_37 AC 110 ms
76,544 KB
testcase_38 AC 161 ms
77,824 KB
testcase_39 AC 116 ms
77,184 KB
testcase_40 AC 112 ms
76,800 KB
testcase_41 AC 177 ms
78,464 KB
testcase_42 AC 286 ms
77,952 KB
testcase_43 AC 125 ms
77,604 KB
testcase_44 AC 132 ms
77,440 KB
testcase_45 AC 104 ms
76,800 KB
testcase_46 AC 173 ms
78,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools

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

INF = float("inf")
dist = [[INF]*N for _ in [0]*N]
route = [[0]*2 for _ in [0]*M]
for i in range(M):
	A,B,C = map(int,input().split())
	A -= 1;	B -= 1
	route[i] = [A,B,C]
	dist[A][B] = dist[B][A] = C

def warshall_floyd(dist):
	for i in range(N):
		dist[i][i] = 0
	for k in range(N):
		for i in range(N):
			for j in range(N):
				d = dist[i][k]+dist[k][j]
				if(dist[i][j] > d):
					dist[i][j] = d
	return 0

warshall_floyd(dist)
ans = INF
rsum = sum(route[i][2] for i in R)
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(route[rlist[i]][0])
				path.append(route[rlist[i]][1])
			else:
				path.append(route[rlist[i]][1])
				path.append(route[rlist[i]][0])
		path.append(N-1)
		s += sum(dist[path[i]][path[i+1]] for i in range(0,len(path)-1,2))
		if(ans > s):
			ans = s

print(ans)
0