結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー sepa38sepa38
提出日時 2022-10-14 22:00:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 381 ms / 2,000 ms
コード長 977 bytes
コンパイル時間 563 ms
コンパイル使用メモリ 86,592 KB
実行使用メモリ 121,936 KB
最終ジャッジ日時 2023-09-08 21:18:07
合計ジャッジ時間 15,534 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
71,476 KB
testcase_01 AC 90 ms
71,648 KB
testcase_02 AC 91 ms
71,540 KB
testcase_03 AC 90 ms
71,568 KB
testcase_04 AC 381 ms
100,292 KB
testcase_05 AC 254 ms
92,300 KB
testcase_06 AC 146 ms
80,808 KB
testcase_07 AC 152 ms
82,008 KB
testcase_08 AC 280 ms
101,008 KB
testcase_09 AC 289 ms
94,740 KB
testcase_10 AC 247 ms
85,000 KB
testcase_11 AC 242 ms
94,432 KB
testcase_12 AC 229 ms
90,800 KB
testcase_13 AC 219 ms
100,256 KB
testcase_14 AC 254 ms
87,232 KB
testcase_15 AC 218 ms
95,220 KB
testcase_16 AC 263 ms
87,056 KB
testcase_17 AC 179 ms
93,692 KB
testcase_18 AC 229 ms
103,060 KB
testcase_19 AC 335 ms
111,688 KB
testcase_20 AC 166 ms
83,240 KB
testcase_21 AC 217 ms
86,832 KB
testcase_22 AC 259 ms
87,224 KB
testcase_23 AC 267 ms
102,884 KB
testcase_24 AC 337 ms
103,072 KB
testcase_25 AC 343 ms
102,856 KB
testcase_26 AC 348 ms
102,928 KB
testcase_27 AC 350 ms
102,852 KB
testcase_28 AC 343 ms
102,976 KB
testcase_29 AC 329 ms
102,952 KB
testcase_30 AC 336 ms
103,176 KB
testcase_31 AC 330 ms
102,848 KB
testcase_32 AC 330 ms
102,952 KB
testcase_33 AC 344 ms
103,196 KB
testcase_34 AC 311 ms
89,456 KB
testcase_35 AC 308 ms
88,796 KB
testcase_36 AC 288 ms
88,944 KB
testcase_37 AC 283 ms
89,776 KB
testcase_38 AC 307 ms
88,552 KB
testcase_39 AC 276 ms
88,892 KB
testcase_40 AC 267 ms
88,940 KB
testcase_41 AC 262 ms
88,608 KB
testcase_42 AC 254 ms
88,428 KB
testcase_43 AC 258 ms
88,616 KB
testcase_44 AC 284 ms
121,936 KB
testcase_45 AC 289 ms
121,624 KB
testcase_46 AC 290 ms
121,792 KB
testcase_47 AC 266 ms
115,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n, m = map(int, input().split())
h = list(map(int, input().split()))
e = [[] for i in range(n)]
re = [[] for i in range(n)]
for i in range(m):
  x, y = map(lambda x: int(x)-1, input().split())
  x, y = sorted([x, y])
  e[x].append(y)
  re[y].append(x)
dp = [[-1, -1] for i in range(n)]
dp[0] = [0, -1]
flg = [0] * n
flg[0] = 1
for u in range(n):
  if flg[u] == 0:
    continue
  for v in e[u]:
    if h[v] > h[u]:
      if dp[u][0] == -1:
        continue
      dp[v][1] = max(dp[v][1], dp[u][0]+h[v]-h[u])
    else:
      dp[v][0] = max(dp[v][0], max(dp[u]))
    flg[v] = 1
print(max(dp[-1]))
dp = [[-1, -1] for i in range(n)]
dp[-1] = [0, -1]
flg = [0] * n
flg[-1] = 1
for u in reversed(range(n)):
  if flg[u] == 0:
    continue
  for v in re[u]:
    if h[v] > h[u]:
      if dp[u][0] == -1:
        continue
      dp[v][1] = max(dp[v][1], dp[u][0]+h[v]-h[u])
    else:
      dp[v][0] = max(dp[v][0], max(dp[u]))
    flg[v] = 1
print(max(dp[0]))
0