結果

問題 No.807 umg tours
ユーザー cmycmy
提出日時 2022-08-18 01:29:51
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 660 bytes
コンパイル時間 445 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 172,128 KB
最終ジャッジ日時 2024-04-15 12:40:01
合計ジャッジ時間 38,387 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
64,640 KB
testcase_01 AC 67 ms
63,744 KB
testcase_02 AC 96 ms
73,856 KB
testcase_03 AC 99 ms
70,272 KB
testcase_04 AC 58 ms
63,332 KB
testcase_05 AC 62 ms
65,408 KB
testcase_06 AC 78 ms
70,784 KB
testcase_07 AC 77 ms
69,504 KB
testcase_08 AC 44 ms
52,608 KB
testcase_09 AC 53 ms
59,136 KB
testcase_10 AC 53 ms
59,392 KB
testcase_11 AC 2,868 ms
145,252 KB
testcase_12 AC 2,277 ms
129,108 KB
testcase_13 AC 3,155 ms
148,164 KB
testcase_14 AC 1,272 ms
108,220 KB
testcase_15 AC 858 ms
99,456 KB
testcase_16 AC 3,099 ms
149,468 KB
testcase_17 AC 3,958 ms
168,436 KB
testcase_18 AC 3,815 ms
166,048 KB
testcase_19 AC 3,606 ms
160,928 KB
testcase_20 AC 1,290 ms
117,828 KB
testcase_21 AC 1,377 ms
120,064 KB
testcase_22 AC 587 ms
93,624 KB
testcase_23 AC 517 ms
90,880 KB
testcase_24 AC 1,266 ms
146,804 KB
testcase_25 TLE -
権限があれば一括ダウンロードができます

ソースコード

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