結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー lloyzlloyz
提出日時 2022-10-14 23:01:36
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,922 bytes
コンパイル時間 435 ms
コンパイル使用メモリ 86,624 KB
実行使用メモリ 106,276 KB
最終ジャッジ日時 2023-09-08 23:24:30
合計ジャッジ時間 7,438 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
71,644 KB
testcase_01 AC 98 ms
71,232 KB
testcase_02 AC 95 ms
71,276 KB
testcase_03 AC 95 ms
71,364 KB
testcase_04 AC 346 ms
106,276 KB
testcase_05 AC 267 ms
93,520 KB
testcase_06 AC 137 ms
83,264 KB
testcase_07 AC 138 ms
82,796 KB
testcase_08 AC 269 ms
100,276 KB
testcase_09 AC 347 ms
97,288 KB
testcase_10 TLE -
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 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from heapq import heapify, heappop, heappush
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    H = list(map(int, input().split()))
    G = defaultdict(list)
    for _ in range(m):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        G[x].append((y, H[y] - H[x]))
        G[y].append((x, H[x] - H[y]))

    DP = [[-1, -1] for _ in range(n)]
    DP[0][0] = 0
    H = [(0, 0, 0)]
    heapify(H)
    while H:
        cnt, cp, up = heappop(H)
        cnt *= -1
        if cnt < DP[cp][up]:
            continue
        if cp == n - 1:
            continue
        for np, d in G[cp]:
            if np < cp:
                continue
            if d > 0:
                if up == 0:
                    if cnt + d <= DP[np][1]:
                        continue
                    DP[np][1] = cnt + d
                    heappush(H, (-DP[np][1], np, 1))
            else:
                if cnt <= DP[np][0]:
                    continue
                DP[np][0] = cnt
                heappush(H, (-DP[np][0], np, 0))
    print(max(DP[n - 1]))

    DP = [[-1, -1] for _ in range(n)]
    DP[n - 1][0] = 0
    H = [(0, n - 1, 0)]
    heapify(H)
    while H:
        cnt, cp, up = heappop(H)
        cnt *= -1
        if cnt < DP[cp][up]:
            continue
        if cp == 0:
            continue
        for np, d in G[cp]:
            if np > cp:
                continue
            if d > 0:
                if up == 0:
                    if cnt + d <= DP[np][1]:
                        continue
                    DP[np][1] = cnt + d
                    heappush(H, (-DP[np][1], np, 1))
            else:
                if cnt <= DP[np][0]:
                    continue
                DP[np][0] = cnt
                heappush(H, (-DP[np][0], np, 0))
    print(max(DP[0]))

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