結果

問題 No.1995 CHIKA Road
ユーザー hiragnhiragn
提出日時 2022-12-14 12:19:07
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 945 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 82,420 KB
実行使用メモリ 848,644 KB
最終ジャッジ日時 2024-04-25 16:38:47
合計ジャッジ時間 2,506 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
67,228 KB
testcase_01 AC 56 ms
67,184 KB
testcase_02 RE -
testcase_03 AC 55 ms
67,184 KB
testcase_04 AC 59 ms
67,504 KB
testcase_05 AC 156 ms
92,868 KB
testcase_06 MLE -
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 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush
from typing import List


def dijkstra(edges: "List[List[(cost, to)]]", start_node: int) -> list:
    hq = []
    heapify(hq)
    dist = [float("inf")] * len(edges)
    heappush(hq, (0, start_node))
    dist[start_node] = 0
    while hq:
        min_cost, now = heappop(hq)
        if min_cost > dist[now]:
            continue
        for cost, nxt in edges[now]:
            if dist[nxt] > dist[now] + cost:
                dist[nxt] = dist[now] + cost
                heappush(hq, (dist[nxt], nxt))
    return dist


def main():
    n, m = map(int, input().split())

    edge = [[] for _ in range(n + 1)]
    for _ in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        edge[a].append([2 * (b - a) - 1, b])
    for i in range(n - 1):
        edge[i].append([2, i + 1])

    ans = dijkstra(edge, 0)[n - 1]
    print(ans)


if __name__ == "__main__":
    main()
0