結果

問題 No.1812 Uribo Road
ユーザー wgrape
提出日時 2024-10-17 17:08:31
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,056 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 82,184 KB
実行使用メモリ 848,632 KB
最終ジャッジ日時 2024-10-17 17:08:36
合計ジャッジ時間 4,061 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 MLE * 1 -- * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M,K = map(int,input().split())
R = list(map(lambda x:int(x) - 1,input().split()))
dic = {}
for i in range(K):
    dic[R[i]] = i

G = [[] for i in range(N)]
for i in range(M):
    a,b,c = map(int,input().split())
    G[a - 1].append([b - 1, c, -1 if i not in dic else dic[i]])
    G[b - 1].append([a - 1, c, -1 if i not in dic else dic[i]])

INF = 1 << 60
dp = [[INF] * N for i in range(1 << N)]

import heapq as hq
q = []

hq.heappush(q, (0, 0, 0)) # コスト、頂点、今まで訪れた道
seen = set() # (v, status)のペアを持つ
goal = (1 << K) - 1
while q:
    cost, v, status = hq.heappop(q)
#    print(v,bin(status)[2:].zfill(2))
    if v == N - 1 and status == goal:
        print(cost)
        break
    if (v, status) in seen:
        continue
    seen.add((v, status))
    for child, c, road in G[v]:
        next_status = status
        if road != -1: # 通るべき道である
            next_status |= (1 << road)
        if (child, next_status) in seen:
            continue
        hq.heappush(q, (cost + c, child, next_status))

0