結果

問題 No.807 umg tours
ユーザー OKCH3COOH
提出日時 2019-11-13 20:54:49
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 874 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 183,936 KB
最終ジャッジ日時 2024-09-21 21:13:36
合計ジャッジ時間 39,530 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

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]:
            if minDist[to] > dist + cost:
                heappush(que, (dist + cost, to))

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

sol()
0