結果

問題 No.1812 Uribo Road
ユーザー ShirotsumeShirotsume
提出日時 2021-12-25 18:51:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,296 bytes
コンパイル時間 938 ms
コンパイル使用メモリ 81,784 KB
実行使用メモリ 844,264 KB
最終ジャッジ日時 2023-10-21 20:29:17
合計ジャッジ時間 68,335 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4,937 ms
77,048 KB
testcase_01 AC 4,938 ms
77,076 KB
testcase_02 AC 4,938 ms
77,088 KB
testcase_03 WA -
testcase_04 AC 4,937 ms
76,744 KB
testcase_05 AC 4,938 ms
77,288 KB
testcase_06 AC 4,938 ms
77,132 KB
testcase_07 AC 4,939 ms
77,220 KB
testcase_08 AC 4,939 ms
78,688 KB
testcase_09 AC 4,938 ms
80,368 KB
testcase_10 AC 4,939 ms
78,996 KB
testcase_11 AC 4,937 ms
79,708 KB
testcase_12 MLE -
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 time
t1 = time.time()

import itertools
import heapq

N,M,K = map(int,input().split())
rlist = list([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 rlist):
		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 = 10 ** 9
import random
rsum = sum(edge[i][2] for i in rlist)
dist = dijkstra(route)
while time.time() - t1 <= 4.9:
    random.shuffle(rlist)
    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