結果

問題 No.807 umg tours
ユーザー rin204
提出日時 2022-04-17 15:40:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 714 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 151,180 KB
最終ジャッジ日時 2024-12-26 09:15:12
合計ジャッジ時間 24,656 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append((b, c))
    edges[b].append((a, c))

inf = 1 << 30
dist = [[inf] * 2 for _ in range(n)]
dist[0][0] = 0
dist[0][1] = 0
hq = [(0, 0, 0)]
while hq:
    d, pos, t = heappop(hq)
    if d > dist[pos][t]:
        continue
    for npos, c in edges[pos]:
        if dist[npos][t] > d + c:
            dist[npos][t] = d + c
            heappush(hq, (d + c, npos, t))
        if t == 0:
            if dist[npos][1] > d :
                dist[npos][1] = d
                heappush(hq, (d, npos, 1))

for d1, d2 in dist:
    print(d1 + d2)
0