結果

問題 No.1814 Uribo Road (Easy)
ユーザー MasKoaTSMasKoaTS
提出日時 2021-11-05 11:33:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,052 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 16,512 KB
最終ジャッジ日時 2024-05-01 17:31:07
合計ジャッジ時間 8,135 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
16,512 KB
testcase_01 AC 48 ms
10,880 KB
testcase_02 AC 32 ms
11,008 KB
testcase_03 AC 32 ms
10,880 KB
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 31 ms
10,880 KB
testcase_06 AC 32 ms
11,008 KB
testcase_07 AC 32 ms
11,008 KB
testcase_08 AC 31 ms
10,880 KB
testcase_09 AC 62 ms
11,136 KB
testcase_10 AC 49 ms
11,136 KB
testcase_11 AC 121 ms
11,648 KB
testcase_12 AC 271 ms
12,160 KB
testcase_13 AC 176 ms
12,032 KB
testcase_14 AC 380 ms
12,544 KB
testcase_15 AC 74 ms
11,904 KB
testcase_16 AC 106 ms
12,544 KB
testcase_17 AC 113 ms
12,416 KB
testcase_18 AC 87 ms
12,416 KB
testcase_19 AC 87 ms
12,416 KB
testcase_20 AC 1,764 ms
14,976 KB
testcase_21 AC 394 ms
11,776 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

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