結果
問題 |
No.1812 Uribo Road
|
ユーザー |
![]() |
提出日時 | 2022-01-16 13:00:55 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,302 bytes |
コンパイル時間 | 267 ms |
コンパイル使用メモリ | 82,584 KB |
実行使用メモリ | 1,111,632 KB |
最終ジャッジ日時 | 2024-11-23 09:44:35 |
合計ジャッジ時間 | 71,351 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 TLE * 9 MLE * 1 |
ソースコード
import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline import heapq INF = 10**18 from collections import defaultdict def main(): n, m, k = map(int, input().split()) R = list(map(int, input().split())) R = [r-1 for r in R] toid = {} for i, r in enumerate(R): toid[r] = i g = [[] for i in range(n)] for i in range(m): a, b, c = map(int, input().split()) a, b = a-1, b-1 if i in toid: j = toid[i] g[a].append((c, b, j)) g[b].append((c, a, j)) else: g[a].append((c, b, -1)) g[b].append((c, a, -1)) import heapq INF = 10**18 hq = [] heapq.heapify(hq) heapq.heappush(hq, (0, 0)) dist = defaultdict(lambda: INF) dist[0] = 0 while hq: d, x = heapq.heappop(hq) if dist[x] < d: continue b, v = divmod(x, n) for c, nv, i in g[v]: if i != -1: nb = b|(1<<i) else: nb = b nx = nb*n+nv if dist[nx] > dist[x]+c: dist[nx] = dist[x]+c heapq.heappush(hq, (dist[nx], nx)) t = ((1<<k)-1)*n+n-1 ans = dist[t] print(ans) if __name__ == '__main__': main()