結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-10 10:47:32 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 979 bytes |
| コンパイル時間 | 168 ms |
| コンパイル使用メモリ | 82,368 KB |
| 実行使用メモリ | 848,376 KB |
| 最終ジャッジ日時 | 2024-07-07 20:49:41 |
| 合計ジャッジ時間 | 7,914 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | MLE * 1 -- * 25 |
ソースコード
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')