結果

問題 No.807 umg tours
ユーザー hedwig100hedwig100
提出日時 2020-04-23 23:18:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,112 ms / 4,000 ms
コード長 871 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 84,648 KB
最終ジャッジ日時 2024-05-03 00:18:54
合計ジャッジ時間 22,423 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,752 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 30 ms
10,880 KB
testcase_03 AC 30 ms
10,752 KB
testcase_04 AC 30 ms
10,880 KB
testcase_05 AC 29 ms
10,880 KB
testcase_06 AC 32 ms
10,880 KB
testcase_07 AC 30 ms
10,880 KB
testcase_08 AC 29 ms
10,752 KB
testcase_09 AC 28 ms
10,880 KB
testcase_10 AC 29 ms
10,752 KB
testcase_11 AC 1,359 ms
60,284 KB
testcase_12 AC 1,128 ms
53,740 KB
testcase_13 AC 1,674 ms
69,556 KB
testcase_14 AC 691 ms
36,844 KB
testcase_15 AC 527 ms
32,992 KB
testcase_16 AC 1,798 ms
73,956 KB
testcase_17 AC 2,074 ms
83,388 KB
testcase_18 AC 2,076 ms
84,108 KB
testcase_19 AC 2,103 ms
84,648 KB
testcase_20 AC 1,022 ms
62,592 KB
testcase_21 AC 1,072 ms
64,896 KB
testcase_22 AC 444 ms
34,400 KB
testcase_23 AC 341 ms
29,468 KB
testcase_24 AC 1,188 ms
66,804 KB
testcase_25 AC 2,112 ms
83,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import heapify,heappush,heappop
input = sys.stdin.readline
INF = 10 ** 16

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

dist = [INF] * n
dist[0] = 0

q = [(0,0)]
heapify(q)

while q:
    d,v = heappop(q)
    if dist[v] < d:
        continue
    for e,cost in G[v]:
        if dist[e] > dist[v] + cost:
            dist[e] = dist[v] + cost
            heappush(q,(dist[e],e))

dist1 = [INF] * n
dist1[0] = 0
heappush(q,(0,0))
while q:
    d,v = heappop(q)
    if dist1[v] < d:
        continue
    for e,cost in G[v]:
        m = min(dist[v],dist1[v] + cost)
        if dist1[e] > m:
            dist1[e] = m
            heappush(q,(dist1[e],e))

print('\n'.join(map(str,[dist[i] + dist1[i] for i in range(n)])))
0