結果

問題 No.807 umg tours
ユーザー ttr
提出日時 2020-06-21 20:32:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,024 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 82,436 KB
実行使用メモリ 153,820 KB
最終ジャッジ日時 2024-07-03 18:23:10
合計ジャッジ時間 25,242 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

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

import heapq
inf = 10**15
d1 = [inf]*N
d2 = [inf]*N
used1 = [0]*N
used2 = [0]*N
h1 = [0]
while h1:
    temp = heapq.heappop(h1)
    u = temp%N
    dist = temp//N
    if used1[u]:
        continue
    d1[u] = dist
    used1[u] = 1
    for e in E[u]:
        r = e//N
        v = e%N
        if used1[v]:
            continue
        heapq.heappush(h1, (r+dist)*N+v)

h2 = []
used2[0] = 1
d2[0] = 0
for e in E[0]:
    heapq.heappush(h2, (0, e//N, e%N))

while h2:
    temp = heapq.heappop(h2)
    u = temp[2]
    dist = temp[0]
    len = temp[1]
    if used2[u]:
        continue
    d2[u] = dist
    used2[u] = 1
    for e in E[u]:
        r = e//N
        v = e%N
        if len >= r:
            heapq.heappush(h2, (dist+r, len, v))
        else:
            heapq.heappush(h2, (dist+len, r, v))

for i in range(N):
    print(d1[i]+d2[i])
0