結果

問題 No.807 umg tours
ユーザー cmycmy
提出日時 2022-05-23 21:50:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,880 ms / 4,000 ms
コード長 660 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 81,832 KB
実行使用メモリ 171,600 KB
最終ジャッジ日時 2023-10-20 17:44:43
合計ジャッジ時間 34,930 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
66,428 KB
testcase_01 AC 56 ms
64,288 KB
testcase_02 AC 83 ms
73,796 KB
testcase_03 AC 72 ms
70,652 KB
testcase_04 AC 55 ms
64,284 KB
testcase_05 AC 60 ms
66,440 KB
testcase_06 AC 76 ms
72,696 KB
testcase_07 AC 70 ms
70,648 KB
testcase_08 AC 39 ms
53,516 KB
testcase_09 AC 45 ms
59,596 KB
testcase_10 AC 45 ms
59,308 KB
testcase_11 AC 2,849 ms
145,036 KB
testcase_12 AC 2,045 ms
128,848 KB
testcase_13 AC 2,924 ms
147,952 KB
testcase_14 AC 1,184 ms
107,948 KB
testcase_15 AC 795 ms
99,288 KB
testcase_16 AC 2,908 ms
149,124 KB
testcase_17 AC 3,732 ms
167,492 KB
testcase_18 AC 3,645 ms
165,356 KB
testcase_19 AC 3,365 ms
160,632 KB
testcase_20 AC 1,185 ms
117,260 KB
testcase_21 AC 1,227 ms
119,788 KB
testcase_22 AC 533 ms
93,572 KB
testcase_23 AC 454 ms
90,296 KB
testcase_24 AC 1,200 ms
146,228 KB
testcase_25 AC 3,880 ms
171,600 KB
権限があれば一括ダウンロードができます

ソースコード

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, f, x = heapq.heappop(q)
    if cost[x][f] is not None:
        continue
    cost[x][f] = c

    for y, cn in e[x]:
        if cost[y][f] is None:
            heapq.heappush(q, (c+cn, f, y))
        if not f and cost[y][1] is None:
            heapq.heappush(q, (c, 1, y))


for i in range(n):
    sys.stdout.write(f"{sum(cost[i])}\n")
0