結果
| 問題 |
No.3386 Up Down Hiking (Python)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-22 13:56:23 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 521 bytes |
| コンパイル時間 | 320 ms |
| コンパイル使用メモリ | 82,376 KB |
| 実行使用メモリ | 99,460 KB |
| 最終ジャッジ日時 | 2025-11-22 13:56:40 |
| 合計ジャッジ時間 | 15,278 ms |
|
ジャッジサーバーID (参考情報) |
judge7 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 30 TLE * 1 -- * 12 |
ソースコード
from collections import deque
N,M=map(int,input().split())
H=list(map(int,input().split()))
G=[[]for _ in range(N)]
for _ in range(M):
a,b=map(int,input().split())
a-=1
b-=1
G[a].append(b)
G[b].append(a)
d=[[-1]*2 for _ in range(N)]
d[0][0]=0
q=deque()
q.append((0,0))
while q:
v,f=q.popleft()
for n in G[v]:
if H[n]>H[v]:
if f==0 and d[n][0]<d[v][f]+1:
d[n][0]=d[v][f]+1
q.append((n,0))
else:
if d[n][1]<d[v][f]+1:
d[n][1]=d[v][f]+1
q.append((n,1))
a=max(d[-1])
print(a+1 if a>=0 else a)