結果
問題 |
No.807 umg tours
|
ユーザー |
|
提出日時 | 2021-02-10 10:49:04 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,055 ms / 4,000 ms |
コード長 | 978 bytes |
コンパイル時間 | 303 ms |
コンパイル使用メモリ | 82,828 KB |
実行使用メモリ | 167,464 KB |
最終ジャッジ日時 | 2024-07-07 20:52:00 |
合計ジャッジ時間 | 11,948 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
import sys from heapq import heappush, heappop INF = 10 ** 14 + 1 def dijkstra(N, G, s): """https://tjkendev.github.io/procon-library/python/graph/dijkstra.html から拝借しています。""" dist = [INF] * N que = [(0, s)] dist[s] = 0 while que: c, v = heappop(que) if dist[v] < c: continue for t, cost in G[v]: if dist[v] + cost < dist[t]: dist[t] = dist[v] + cost heappush(que, (dist[t], t)) return dist input = sys.stdin.buffer.readline N, M = map(int, input().split()) G = [[] for _ in range(2 * N)] for i in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 G[a].append((b, c)) G[b].append((a, c)) G[a + N].append((b + N, c)) G[b + N].append((a + N, c)) G[a].append((b + N, 0)) G[b].append((a + N, 0)) dist = dijkstra(2 * N, G, 0) ans = [dist[i] + dist[i + N] for i in range(N)] ans[0] = 0 print(*ans, sep='\n')