結果
問題 |
No.1812 Uribo Road
|
ユーザー |
![]() |
提出日時 | 2024-10-17 17:11:53 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,171 bytes |
コンパイル時間 | 349 ms |
コンパイル使用メモリ | 82,408 KB |
実行使用メモリ | 638,268 KB |
最終ジャッジ日時 | 2024-10-17 17:12:02 |
合計ジャッジ時間 | 9,436 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 8 MLE * 1 -- * 21 |
ソースコード
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]]) import heapq as hq q = [] hq.heappush(q, (0, 0, 0)) # コスト、頂点、今まで訪れた道 seen = set() # (v, status)のペアを持つ INF = 1 << 60 best = [[INF] * N for i in range(1 << K)] 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 if best[next_status][child] <= cost + c: continue best[next_status][child] = cost + c hq.heappush(q, (cost + c, child, next_status))