結果

問題 No.807 umg tours
ユーザー kohei2019
提出日時 2022-04-14 01:19:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,658 ms / 4,000 ms
コード長 723 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 82,572 KB
実行使用メモリ 167,712 KB
最終ジャッジ日時 2024-12-24 03:21:38
合計ジャッジ時間 18,372 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

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

h = [(0,0)]
INF = float('INF')
cost = [INF]*(2*N)
cost[0] = 0
cost[N] = 0
used = [False]*(2*N)
while h:
    c,n = heapq.heappop(h)
    if used[n]:
        continue
    used[n] = True
    for nex,cos in lsg[n]:
        if used[nex]:
            continue
        if cost[nex] > c + cos:
            cost[nex] = c + cos
            heapq.heappush(h, (c+cos,nex))
for i in range(N):
    print(cost[i]+cost[i+N])
0