結果

問題 No.1814 Uribo Road (Easy)
ユーザー lloyz
提出日時 2022-01-15 23:19:39
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 571 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 477,968 KB
最終ジャッジ日時 2024-11-22 05:28:31
合計ジャッジ時間 129,216 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 TLE * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush

n, m, k = map(int, input().split())
R = list(map(int, input().split()))
Rset = set(R)
edge = [[] for _ in range(n + 1)]
for i in range(1, m + 1):
    a, b, c = map(int, input().split())
    edge[a].append((b, c, i))
    edge[b].append((a, c, i))

H = [(0, 1, set())]
while H:
    res, curr, road = heappop(H)
    if road == Rset and curr == n:
        print(res)
        break
    for np, nc, idx in edge[curr]:
        nroad = road.copy()
        if idx in Rset:
            nroad.add(idx)
        heappush(H, (res + nc, np, nroad))
0