結果

問題 No.807 umg tours
ユーザー cmycmy
提出日時 2022-05-23 19:16:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 829 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 81,844 KB
実行使用メモリ 202,344 KB
最終ジャッジ日時 2023-10-20 17:42:50
合計ジャッジ時間 14,405 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
70,756 KB
testcase_01 AC 65 ms
70,728 KB
testcase_02 AC 96 ms
76,412 KB
testcase_03 AC 91 ms
76,092 KB
testcase_04 WA -
testcase_05 AC 75 ms
72,812 KB
testcase_06 AC 95 ms
76,228 KB
testcase_07 AC 88 ms
76,088 KB
testcase_08 AC 38 ms
53,584 KB
testcase_09 AC 44 ms
60,028 KB
testcase_10 AC 48 ms
62,224 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
e = [[] for _ in range(n)]
for _ in range(m):
    ai, bi, ci = map(int, input().split())
    e[ai-1].append((bi-1, ci))
    e[bi-1].append((ai-1, ci))

q = [(0, 0)]
c1 = [None] * n
while q:
    c, x = heapq.heappop(q)
    if c1[x] is not None:
        continue
    c1[x] = c
    for y, cn in e[x]:
        if c1[y] is not None:
            continue
        heapq.heappush(q, (c+cn, y))

q = [(0, 0, 0)]
c2 = [float("inf")] * n
while q:
    c, cut, x = heapq.heappop(q)
    c2[x] = min(c2[x], c)
    for y, cn in e[x]:
        if c2[y] < float("inf"):
            continue
        if cn > cut:
            heapq.heappush(q, (c+cut, cn, y))
        else:
            heapq.heappush(q, (c+cn, cut, y))

for i in range(n):
    print(c1[i] + c2[i])
0