結果

問題 No.807 umg tours
ユーザー tobusakana
提出日時 2022-12-01 21:13:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,658 ms / 4,000 ms
コード長 907 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 235,952 KB
最終ジャッジ日時 2024-10-09 01:44:37
合計ジャッジ時間 18,736 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
G = [[] for i in range(2 * N)]
for _ in range(M):
    a,b,c = map(int,readline().split())
    a -= 1
    b -= 1
    G[a].append([b, c])
    G[b].append([a, c])
    G[a].append([b + N, 0])
    G[b].append([a + N, 0])
    G[a + N].append([b + N, c])
    G[b + N].append([a + N, c])

INF = 1 << 60
dist = [0] * (2 * N)
best = [INF] * (2 * N)
visited = [False] * (2 * N)
import heapq as hq
q = []
hq.heappush(q, (0, 0))
while q:
    d,v = hq.heappop(q)
    if visited[v]:
        continue
    visited[v] = True
    dist[v] = d
    for child, cost in G[v]:
        if visited[child]:
            continue
        if best[child] <= d + cost:
            continue
        best[child] = d + cost
        hq.heappush(q, (d + cost, child))
        
print(0)
for i in range(1, N):
    print(dist[i] + dist[i + N])
    
    
            





0