結果
問題 |
No.807 umg tours
|
ユーザー |
|
提出日時 | 2022-01-23 09:33:33 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,387 ms / 4,000 ms |
コード長 | 902 bytes |
コンパイル時間 | 289 ms |
コンパイル使用メモリ | 82,564 KB |
実行使用メモリ | 174,260 KB |
最終ジャッジ日時 | 2024-11-29 06:09:29 |
合計ジャッジ時間 | 17,241 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
from heapq import heappop, heappush INF = 1 << 60 def dijkstra(s, edge): n = len(edge) dist = [INF] * n dist[s] = 0 hq = [] heappush(hq, (dist[s], s)) while hq: dist_v, v = heappop(hq) if dist_v > dist[v]: continue for cost, nx in edge[v]: if dist[nx] > dist[v] + cost: dist[nx] = dist[v] + cost heappush(hq, (dist[nx], nx)) return dist N, M = map(int, input().split()) G = [[] for _ in range(2 * N)] for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 G[a].append((c, b)) G[b].append((c, a)) G[a].append((0, b + N)) G[b].append((0, a + N)) G[a + N].append((c, b + N)) G[b + N].append((c, a + N)) for i in range(N): G[i].append((0, i + N)) dist = dijkstra(0, G) for i in range(N): ans = dist[i] + dist[i + N] print(ans)