結果

問題 No.807 umg tours
ユーザー H3PO4H3PO4
提出日時 2021-02-10 10:47:32
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 979 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 845,292 KB
最終ジャッジ日時 2023-09-22 04:02:41
合計ジャッジ時間 7,059 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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