結果

問題 No.1812 Uribo Road
ユーザー rin204
提出日時 2022-01-20 22:39:03
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 940 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,896 KB
実行使用メモリ 685,248 KB
最終ジャッジ日時 2024-11-24 08:22:46
合計ジャッジ時間 64,795 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 MLE * 1
other AC * 21 TLE * 8 MLE * 1
権限があれば一括ダウンロードができます

ソースコード

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