結果

問題 No.807 umg tours
ユーザー cmycmy
提出日時 2022-05-23 21:29:06
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 597 bytes
コンパイル時間 1,274 ms
コンパイル使用メモリ 81,592 KB
実行使用メモリ 195,172 KB
最終ジャッジ日時 2023-10-20 17:43:59
合計ジャッジ時間 7,335 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
73,200 KB
testcase_01 AC 77 ms
73,696 KB
testcase_02 AC 97 ms
76,224 KB
testcase_03 AC 93 ms
76,228 KB
testcase_04 AC 69 ms
70,544 KB
testcase_05 AC 80 ms
74,392 KB
testcase_06 AC 102 ms
76,340 KB
testcase_07 AC 102 ms
76,428 KB
testcase_08 AC 44 ms
59,232 KB
testcase_09 AC 53 ms
63,892 KB
testcase_10 AC 55 ms
63,900 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
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, 0)]
cost = [[None, None] for _ in range(n)]
cost[0][1] = 0
while q:
    c, used, x = heapq.heappop(q)
    if cost[x][used] is not None:
        continue
    cost[x][used] = c

    for y, cn in e[x]:
        heapq.heappush(q, (c+cn, used, y))
        if not used:
            heapq.heappush(q, (c, 1, y))

for i in range(n):
    print(sum(cost[i]))
0