結果
問題 | No.807 umg tours |
ユーザー |
|
提出日時 | 2022-08-18 01:29:51 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 3,805 ms / 4,000 ms |
コード長 | 660 bytes |
コンパイル時間 | 602 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 171,864 KB |
最終ジャッジ日時 | 2024-10-05 08:40:44 |
合計ジャッジ時間 | 34,702 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
import heapq import sys input = sys.stdin.readline n, m = map(int, input().split()) e = [[] for _ in range(n)] for _ in range(m): ai, bi, ci = map(int, input().split()) e[ai-1].append((bi-1, ci)) e[bi-1].append((ai-1, ci)) q = [(0, 0, 0)] cost = [[None, None] for _ in range(n)] cost[0][1] = 0 while q: c, f, x = heapq.heappop(q) if cost[x][f] is not None: continue cost[x][f] = c for y, cn in e[x]: if cost[y][f] is None: heapq.heappush(q, (c+cn, f, y)) if not f and cost[y][1] is None: heapq.heappush(q, (c, 1, y)) for i in range(n): sys.stdout.write(f"{sum(cost[i])}\n")