結果

問題 No.807 umg tours
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-11-13 20:56:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,611 ms / 4,000 ms
コード長 882 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 171,924 KB
最終ジャッジ日時 2024-11-23 19:44:56
合計ジャッジ時間 17,830 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop

def sol():
    N, M = map(int, input().split())
    edges = [[] for _ in range(2 * N)]

    for _ in range(M):
        fr, to, cost = map(int, input().split())
        fr -= 1
        to -= 1
        edges[fr].append((to, cost))
        edges[to].append((fr, cost))
        edges[fr + N].append((to + N, cost))
        edges[to + N].append((fr + N, cost))
        edges[fr].append((to + N, 0))
        edges[to].append((fr + N, 0))

    que = [(0, 0)]
    minDist = [float('inf')] * (2 * N)
    while que:
        dist, now = heappop(que)
        if minDist[now] <= dist:
            continue
        minDist[now] = dist
        for to, cost in edges[now]:
            d = dist + cost
            if minDist[to] > d:
                heappush(que, (d, to))

    print(0)
    for i in range(1, N):
        print(minDist[i] + minDist[i + N])

sol()
0