結果
問題 | No.1812 Uribo Road |
ユーザー | Shirotsume |
提出日時 | 2022-01-01 01:34:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 900 ms / 5,000 ms |
コード長 | 1,964 bytes |
コンパイル時間 | 191 ms |
コンパイル使用メモリ | 82,228 KB |
実行使用メモリ | 99,684 KB |
最終ジャッジ日時 | 2024-11-14 12:17:12 |
合計ジャッジ時間 | 11,808 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
53,416 KB |
testcase_01 | AC | 39 ms
53,296 KB |
testcase_02 | AC | 51 ms
64,556 KB |
testcase_03 | AC | 146 ms
81,256 KB |
testcase_04 | AC | 39 ms
53,136 KB |
testcase_05 | AC | 40 ms
53,856 KB |
testcase_06 | AC | 41 ms
54,996 KB |
testcase_07 | AC | 81 ms
76,868 KB |
testcase_08 | AC | 177 ms
78,912 KB |
testcase_09 | AC | 207 ms
78,712 KB |
testcase_10 | AC | 143 ms
77,792 KB |
testcase_11 | AC | 160 ms
78,168 KB |
testcase_12 | AC | 473 ms
91,628 KB |
testcase_13 | AC | 264 ms
87,392 KB |
testcase_14 | AC | 287 ms
86,772 KB |
testcase_15 | AC | 447 ms
83,384 KB |
testcase_16 | AC | 393 ms
85,212 KB |
testcase_17 | AC | 779 ms
95,952 KB |
testcase_18 | AC | 314 ms
84,480 KB |
testcase_19 | AC | 855 ms
99,292 KB |
testcase_20 | AC | 900 ms
99,684 KB |
testcase_21 | AC | 736 ms
95,592 KB |
testcase_22 | AC | 570 ms
92,784 KB |
testcase_23 | AC | 147 ms
78,092 KB |
testcase_24 | AC | 52 ms
64,564 KB |
testcase_25 | AC | 294 ms
81,704 KB |
testcase_26 | AC | 162 ms
77,524 KB |
testcase_27 | AC | 297 ms
82,500 KB |
testcase_28 | AC | 452 ms
84,244 KB |
testcase_29 | AC | 41 ms
54,388 KB |
testcase_30 | AC | 193 ms
78,340 KB |
testcase_31 | AC | 597 ms
89,468 KB |
testcase_32 | AC | 122 ms
77,396 KB |
testcase_33 | AC | 388 ms
88,940 KB |
ソースコード
INF = 10 ** 18 def dijkstra(s, n, graph): import heapq dist = [INF] * n dist[s] = 0 bef = [0] * n bef[s] = s hq = [(0, s)] #距離、地点を記録したヒープを作る heapq.heapify(hq) visit = [False] * n #訪れたかの判定 while(len(hq) > 0): c, v = heapq.heappop(hq) #ヒープから地点を1つ持ってくる visit[v] = True if c > dist[v]: continue for to, cost in graph[v]: if visit[to] == False and dist[v] + cost < dist[to]: dist[to] = cost + dist[v] bef[to] = v heapq.heappush(hq, (dist[to], to)) ''' return bef ''' return dist n, m, k = map(int,input().split()) r = list(map(int,input().split())) graph = [[] for _ in range(n)] edge = [None] * k dist = [[] for _ in range(n)] for i in range(m): a, b, c = map(int,input().split()) a -= 1 b -= 1 if b < a: a, b = b, a graph[a].append((b, c)) graph[b].append((a, c)) if i + 1 in r: edge[r.index(i + 1)] = (a, b, c) dist[0] = dijkstra(0, n, graph) dist[n - 1] = dijkstra(n - 1, n, graph) for x, y, z in edge: dist[x] = dijkstra(x, n, graph) dist[y] = dijkstra(y, n, graph) dp = [[[INF] * 2 for _ in range(k + 1)] for _ in range(2 ** k + 1)] for i in range(k): for j in range(2): dp[2 ** i][i][j] = dist[0][edge[i][1 - j]] + edge[i][2] for bit in range(2 ** k): for now in range(k): if not (1 & (bit >> now)): continue for to in range(k): if (1 & (bit >> to)): continue for v in range(2): for u in range(2): dp[bit + 2 ** to][to][v] = min(dp[bit + 2 ** to][to][v], dp[bit][now][u] + dist[edge[now][u]][edge[to][1 - v]] + edge[to][2]) ans = INF for i in range(k): for v in range(2): ans = min(ans, dp[2 ** k - 1][i][v] + dist[n - 1][edge[i][v]]) print(ans)