結果

問題 No.807 umg tours
ユーザー ああいいああいい
提出日時 2021-12-29 18:40:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,583 ms / 4,000 ms
コード長 1,130 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 145,044 KB
最終ジャッジ日時 2024-04-15 00:23:53
合計ジャッジ時間 24,361 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
62,464 KB
testcase_01 AC 66 ms
64,768 KB
testcase_02 AC 64 ms
66,048 KB
testcase_03 AC 61 ms
65,408 KB
testcase_04 AC 53 ms
61,824 KB
testcase_05 AC 57 ms
62,848 KB
testcase_06 AC 64 ms
66,304 KB
testcase_07 AC 59 ms
64,748 KB
testcase_08 AC 41 ms
52,864 KB
testcase_09 AC 44 ms
53,760 KB
testcase_10 AC 45 ms
54,144 KB
testcase_11 AC 1,029 ms
107,904 KB
testcase_12 AC 1,442 ms
114,508 KB
testcase_13 AC 1,676 ms
121,364 KB
testcase_14 AC 838 ms
98,324 KB
testcase_15 AC 586 ms
92,672 KB
testcase_16 AC 1,573 ms
123,060 KB
testcase_17 AC 2,346 ms
136,748 KB
testcase_18 AC 2,178 ms
134,828 KB
testcase_19 AC 2,038 ms
131,680 KB
testcase_20 AC 1,109 ms
108,516 KB
testcase_21 AC 1,125 ms
110,000 KB
testcase_22 AC 524 ms
89,472 KB
testcase_23 AC 479 ms
86,984 KB
testcase_24 AC 1,184 ms
137,676 KB
testcase_25 AC 2,583 ms
145,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

import heapq
C = 10 ** 16
dist = [C] * (N + 1)
dist[1] = 0
q = []
heapq.heapify(q)
heapq.heappush(q,(0,1))
while len(q):
    d,index = heapq.heappop(q)
    if d > dist[index]:
        continue
    for v,c in G[index]:
        if dist[v] > d + c:
            dist[v] = d + c
            heapq.heappush(q,(d+c,v))
dist2 = [C] * (N + 1)
dist2[1] = 0
heapq.heappush(q,(0,1,False))
while len(q):
    d,index,flag = heapq.heappop(q)
    if flag and d > dist2[index]:
        continue
    for v,c in G[index]:
        if flag:
            if dist2[v] > dist2[index] + c:
                dist2[v] = dist2[index] + c
                heapq.heappush(q,(d + c,v,True))
        else:
            if dist2[v] > dist[index]:
                dist2[v] = dist[index]
                heapq.heappush(q,(dist[index],v,True))
            if dist[v] >= dist[index] + c:
                heapq.heappush(q,(dist[index] + c,v,False))
for i in range(N):
    print(dist[i+1] + dist2[i+1])
    
0