結果

問題 No.1812 Uribo Road
ユーザー 👑 rin204rin204
提出日時 2022-01-20 22:39:03
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 940 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 82,256 KB
実行使用メモリ 419,980 KB
最終ジャッジ日時 2024-05-03 09:29:06
合計ジャッジ時間 8,272 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
54,380 KB
testcase_01 AC 37 ms
54,040 KB
testcase_02 AC 35 ms
55,056 KB
testcase_03 AC 123 ms
77,392 KB
testcase_04 AC 35 ms
52,716 KB
testcase_05 AC 35 ms
54,576 KB
testcase_06 AC 33 ms
52,872 KB
testcase_07 AC 43 ms
61,192 KB
testcase_08 AC 219 ms
78,084 KB
testcase_09 AC 233 ms
78,804 KB
testcase_10 AC 173 ms
77,852 KB
testcase_11 AC 138 ms
77,344 KB
testcase_12 TLE -
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 #

from heapq import *

n, m, k = map(int, input().split())
R = list(map(int, input().split()))
R = {r - 1:1 << i for i, r in enumerate(R)}
edges = [[] for _ in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    if i in R:
        d = R[i]
    else:
        d = -1
    edges[a].append((b, c, d))
    edges[b].append((a, c, d))
    
inf = 1 << 40
dist = [[inf] * (1 << k) for _ in range(n)]
dist[0][0] = 0
hq = [0]

while hq:
    tmp = heappop(hq)
    bit = tmp % 10000
    tmp //= 10000
    pos = tmp % 10000
    d = tmp // 10000
    if d > dist[pos][bit]:
        continue
    
    for npos, c, dbit in edges[pos]:
        if dbit == -1:
            nbit = bit
        else:
            nbit = bit | dbit
        
        if dist[npos][nbit] > c + d:
            dist[npos][nbit] = c + d
            tmp = (c + d) * 100000000 + npos * 10000 + nbit
            heappush(hq, tmp)
print(dist[-1][-1])
0