結果

問題 No.807 umg tours
ユーザー OKCH3COOH
提出日時 2019-11-13 20:58:08
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 3,906 ms / 4,000 ms
コード長 942 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 182,116 KB
最終ジャッジ日時 2024-11-23 19:48:03
合計ジャッジ時間 36,014 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop

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

    edges[0].append((N, 0))

    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))
                minDist[to] = d

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

sol()
0