結果
| 問題 |
No.1812 Uribo Road
|
| コンテスト | |
| ユーザー |
wgrape
|
| 提出日時 | 2024-10-17 17:09:42 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,001 bytes |
| コンパイル時間 | 464 ms |
| コンパイル使用メモリ | 82,456 KB |
| 実行使用メモリ | 275,676 KB |
| 最終ジャッジ日時 | 2024-10-17 17:09:52 |
| 合計ジャッジ時間 | 9,771 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 8 TLE * 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)のペアを持つ
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))
wgrape