結果
問題 | No.1812 Uribo Road |
ユーザー | tobusakana |
提出日時 | 2022-10-23 20:16:52 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,340 bytes |
コンパイル時間 | 469 ms |
コンパイル使用メモリ | 87,116 KB |
実行使用メモリ | 458,088 KB |
最終ジャッジ日時 | 2023-09-15 05:44:49 |
合計ジャッジ時間 | 10,389 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 80 ms
71,208 KB |
testcase_01 | AC | 82 ms
71,512 KB |
testcase_02 | AC | 80 ms
71,500 KB |
testcase_03 | AC | 273 ms
80,636 KB |
testcase_04 | AC | 78 ms
71,300 KB |
testcase_05 | AC | 79 ms
71,268 KB |
testcase_06 | AC | 80 ms
71,192 KB |
testcase_07 | AC | 87 ms
75,716 KB |
testcase_08 | AC | 407 ms
82,084 KB |
testcase_09 | AC | 786 ms
88,764 KB |
testcase_10 | AC | 342 ms
79,776 KB |
testcase_11 | AC | 243 ms
79,604 KB |
testcase_12 | TLE | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
ソースコード
import sys readline = sys.stdin.readline # dp[v][S] = 今までに触った猪の集合がSでvにいるときの最小コスト N,M,K = map(int,readline().split()) R = list(map(int,readline().split())) Rdic = {} # 道の番号から猪の番号を導く for i in range(K): Rdic[R[i] - 1] = i G = [[] for i in range(N)] for i in range(M): a,b,c = map(int,readline().split()) ino = -1 if i in Rdic: # 道の番号が含まれる ino = Rdic[i] # イノシシの番号に変換 G[a - 1].append([b - 1, c, ino]) G[b - 1].append([a - 1, c, ino]) INF = 1 << 60 best = [[INF] * (1 << K) for i in range(N)] import heapq as hq q = [] hq.heappush(q, (0, 0, 0)) # 距離、頂点、今までに触った猪の集合 complete = (1 << K) - 1 while q: d,v,status = hq.heappop(q) if best[v][status] < d: continue best[v][status] = d if v == N - 1 and status == complete: print(best[v][status]) break for child, cost, ino in G[v]: if ino != -1: next_status = status | (1 << ino) if best[child][next_status] <= d + cost: continue best[child][next_status] = d + cost hq.heappush(q, (d + cost, child, status | (1 << ino))) else: if best[child][status] <= d + cost: continue best[child][status] = d + cost hq.heappush(q, (d + cost, child, status))