結果
問題 |
No.1812 Uribo Road
|
ユーザー |
|
提出日時 | 2022-01-14 23:21:56 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 884 bytes |
コンパイル時間 | 194 ms |
コンパイル使用メモリ | 82,476 KB |
実行使用メモリ | 1,118,200 KB |
最終ジャッジ日時 | 2024-11-20 14:37:23 |
合計ジャッジ時間 | 78,003 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 14 TLE * 11 MLE * 5 |
ソースコード
import sys r = sys.stdin N,M,K = map(int,r.readline().split()) R = list(map(int,r.readline().split())) Rset = set(R) G = [[] for _ in range(N+1)] #D = {v:i for i,v in enumerate(sorted(set(R)))} edge = dict() for i in range(M): a,b,c = map(int,r.readline().split()) G[a].append((b,c)) G[b].append((a,c)) if i + 1 not in Rset:continue for j in range(K): if R[j] == i + 1: edge[(a,b)] = j edge[(b,a)] = j C = 10 ** 15 dp = [[C] * (1<<K) for _ in range(N+1)] dp[0][0] = 0 import heapq q = [] heapq.heapify(q) heapq.heappush(q,(0,1,0)) while q: d,now,S = heapq.heappop(q) if d > dp[now][S]:continue for v,c in G[now]: if (now,v) in edge: T = S | (1 << edge[(now,v)]) else:T = S if dp[v][T] > d + c: dp[v][T] = d+c heapq.heappush(q,(d+c,v,T)) print(dp[N][(1<<K)-1])