結果

問題 No.807 umg tours
ユーザー H3PO4H3PO4
提出日時 2021-02-10 10:49:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,277 ms / 4,000 ms
コード長 978 bytes
コンパイル時間 1,692 ms
コンパイル使用メモリ 86,764 KB
実行使用メモリ 168,988 KB
最終ジャッジ日時 2023-09-22 04:04:42
合計ジャッジ時間 14,521 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
75,356 KB
testcase_01 AC 82 ms
75,488 KB
testcase_02 AC 84 ms
75,560 KB
testcase_03 AC 83 ms
75,720 KB
testcase_04 AC 82 ms
75,568 KB
testcase_05 AC 82 ms
75,704 KB
testcase_06 AC 82 ms
75,568 KB
testcase_07 AC 82 ms
75,720 KB
testcase_08 AC 74 ms
71,464 KB
testcase_09 AC 75 ms
71,112 KB
testcase_10 AC 74 ms
71,388 KB
testcase_11 AC 670 ms
136,956 KB
testcase_12 AC 691 ms
127,828 KB
testcase_13 AC 891 ms
146,304 KB
testcase_14 AC 512 ms
107,140 KB
testcase_15 AC 391 ms
100,656 KB
testcase_16 AC 908 ms
148,032 KB
testcase_17 AC 1,220 ms
163,880 KB
testcase_18 AC 1,277 ms
163,564 KB
testcase_19 AC 1,112 ms
161,336 KB
testcase_20 AC 613 ms
123,596 KB
testcase_21 AC 608 ms
125,904 KB
testcase_22 AC 321 ms
98,056 KB
testcase_23 AC 285 ms
94,728 KB
testcase_24 AC 546 ms
152,160 KB
testcase_25 AC 1,169 ms
168,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import heappush, heappop

INF = 10 ** 14 + 1


def dijkstra(N, G, s):
    """https://tjkendev.github.io/procon-library/python/graph/dijkstra.html から拝借しています。"""
    dist = [INF] * N
    que = [(0, s)]
    dist[s] = 0
    while que:
        c, v = heappop(que)
        if dist[v] < c:
            continue
        for t, cost in G[v]:
            if dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                heappush(que, (dist[t], t))
    return dist


input = sys.stdin.buffer.readline

N, M = map(int, input().split())

G = [[] for _ in range(2 * N)]
for i in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append((b, c))
    G[b].append((a, c))
    G[a + N].append((b + N, c))
    G[b + N].append((a + N, c))
    G[a].append((b + N, 0))
    G[b].append((a + N, 0))
dist = dijkstra(2 * N, G, 0)
ans = [dist[i] + dist[i + N] for i in range(N)]
ans[0] = 0
print(*ans, sep='\n')
0