結果

問題 No.807 umg tours
ユーザー AEnAEn
提出日時 2022-05-18 09:57:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 834 bytes
コンパイル時間 1,765 ms
コンパイル使用メモリ 86,644 KB
実行使用メモリ 112,852 KB
最終ジャッジ日時 2023-10-14 16:21:52
合計ジャッジ時間 19,161 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 87 ms
76,124 KB
testcase_07 WA -
testcase_08 AC 71 ms
71,196 KB
testcase_09 AC 72 ms
71,112 KB
testcase_10 AC 71 ms
71,372 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 TLE -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
INF = float('inf')

N, M = map(int, input().split())
adj = [[] for _ in range(N)]
for i in range(M):
    s, t, d = map(int, input().split())
    s -= 1
    t -= 1
    adj[s].append((t, d))
    adj[t].append((s, d))

def dijkstra(s, n):
    dist = [INF] * n
    hq = [(0, s)]
    dist[s] = 0
    seen = [False] * n
    # 経路復元用
    # prev = [-1]*n
    while hq:
        v = heappop(hq)[1]
        seen[v] = True
        for to, cost in adj[v]:
            if seen[to] == False and dist[v] + cost < dist[to]:
                dist[to] = dist[v] + cost
                # prev[to] = v
                heappush(hq, (dist[to], to))
    return dist
d = dijkstra(0, N)

print(0)
for i in range(1,N):
    res = float('inf')
    for b, c in adj[i]:
        res = min(res, d[b], c)
    print(res+d[i])
0