結果

問題 No.1995 CHIKA Road
ユーザー hiragnhiragn
提出日時 2022-12-14 12:18:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 945 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 527,948 KB
最終ジャッジ日時 2024-04-25 16:38:20
合計ジャッジ時間 4,734 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
18,468 KB
testcase_01 AC 37 ms
11,520 KB
testcase_02 MLE -
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 -- -
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