結果

問題 No.807 umg tours
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-19 01:53:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,112 ms / 4,000 ms
コード長 875 bytes
コンパイル時間 887 ms
コンパイル使用メモリ 81,636 KB
実行使用メモリ 152,984 KB
最終ジャッジ日時 2023-10-21 08:44:45
合計ジャッジ時間 28,771 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
61,872 KB
testcase_01 AC 53 ms
61,928 KB
testcase_02 AC 56 ms
64,000 KB
testcase_03 AC 56 ms
64,000 KB
testcase_04 AC 50 ms
61,876 KB
testcase_05 AC 50 ms
61,876 KB
testcase_06 AC 54 ms
62,020 KB
testcase_07 AC 54 ms
64,000 KB
testcase_08 AC 41 ms
53,404 KB
testcase_09 AC 42 ms
53,404 KB
testcase_10 AC 42 ms
53,404 KB
testcase_11 AC 1,269 ms
111,852 KB
testcase_12 AC 1,623 ms
118,652 KB
testcase_13 AC 1,960 ms
126,600 KB
testcase_14 AC 937 ms
100,352 KB
testcase_15 AC 650 ms
94,768 KB
testcase_16 AC 2,054 ms
128,548 KB
testcase_17 AC 2,789 ms
147,004 KB
testcase_18 AC 2,661 ms
144,352 KB
testcase_19 AC 2,312 ms
139,312 KB
testcase_20 AC 1,129 ms
115,128 KB
testcase_21 AC 1,134 ms
116,076 KB
testcase_22 AC 517 ms
91,980 KB
testcase_23 AC 426 ms
88,184 KB
testcase_24 AC 1,204 ms
145,412 KB
testcase_25 AC 3,112 ms
152,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 10**18

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]*2 for _ in range(N)]
dist[0][0] = 0
dist[0][1] = 0
que = []
heapq.heappush(que, (0, 0, 0))  # dist, node, used
heapq.heappush(que, (0, 0, 1))
while que:
    ds, s, used = heapq.heappop(que)
    if dist[s][used] < ds:
        continue
    for t, dt in G[s]:
        if dist[t][used] > ds + dt:
            dist[t][used] = ds + dt
            heapq.heappush(que, (ds + dt, t, used))
        if not used:
            if dist[t][used + 1] > ds:
                dist[t][used + 1] = ds
                heapq.heappush(que, (ds, t, used + 1))

for d in dist:
    print(sum(d))
0