結果

問題 No.807 umg tours
ユーザー hedwig100hedwig100
提出日時 2020-04-23 23:18:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,870 ms / 4,000 ms
コード長 871 bytes
コンパイル時間 447 ms
コンパイル使用メモリ 11,072 KB
実行使用メモリ 82,044 KB
最終ジャッジ日時 2023-08-15 12:48:47
合計ジャッジ時間 19,653 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,320 KB
testcase_01 AC 16 ms
8,328 KB
testcase_02 AC 17 ms
8,104 KB
testcase_03 AC 16 ms
8,380 KB
testcase_04 AC 15 ms
8,464 KB
testcase_05 AC 16 ms
8,388 KB
testcase_06 AC 17 ms
8,108 KB
testcase_07 AC 16 ms
8,452 KB
testcase_08 AC 15 ms
8,064 KB
testcase_09 AC 14 ms
8,232 KB
testcase_10 AC 15 ms
8,340 KB
testcase_11 AC 1,167 ms
57,676 KB
testcase_12 AC 975 ms
51,416 KB
testcase_13 AC 1,442 ms
67,064 KB
testcase_14 AC 556 ms
34,436 KB
testcase_15 AC 455 ms
30,572 KB
testcase_16 AC 1,571 ms
71,476 KB
testcase_17 AC 1,795 ms
81,052 KB
testcase_18 AC 1,819 ms
81,428 KB
testcase_19 AC 1,870 ms
82,044 KB
testcase_20 AC 875 ms
60,184 KB
testcase_21 AC 922 ms
62,536 KB
testcase_22 AC 364 ms
31,884 KB
testcase_23 AC 263 ms
26,852 KB
testcase_24 AC 980 ms
65,088 KB
testcase_25 AC 1,763 ms
80,096 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