結果

問題 No.807 umg tours
ユーザー sinsincoscos
提出日時 2019-03-17 13:35:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,462 ms / 4,000 ms
コード長 854 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 81,872 KB
実行使用メモリ 165,116 KB
最終ジャッジ日時 2024-11-23 18:49:21
合計ジャッジ時間 16,862 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush
import sys
input = sys.stdin.readline
def solve() : 
    N, M = map(int, input().split())

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

    dist=[float('inf')]*(2*N)
    dist[0]=dist[N]=0

    pq = []
    heappush(pq, (0,0))
    heappush(pq, (0,N))
    while pq:
        d, cur = heappop(pq)
        if d > dist[cur]: continue

        for cost, to in edge[cur]:
            if dist[to]>d+cost : 
                dist[to]=d+cost
                heappush(pq, (d+cost,to))
    for i in range(N) :
        print(dist[i]+dist[i+N])
solve()
0