結果
| 問題 |
No.3386 Up Down Hiking (Python)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-22 14:14:02 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 495 bytes |
| コンパイル時間 | 383 ms |
| コンパイル使用メモリ | 82,592 KB |
| 実行使用メモリ | 99,132 KB |
| 最終ジャッジ日時 | 2025-11-22 14:14:19 |
| 合計ジャッジ時間 | 16,397 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge7 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 41 TLE * 1 -- * 1 |
ソースコード
import heapq
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)
def b(v):
d=[-1 for _ in range(N)]
d[v]=0
q=[(H[v],v)]
while q:
_,v=heapq.heappop(q)
for n in G[v]:
if H[v]<H[n] and d[n]<d[v]+1:
d[n]=d[v]+1
heapq.heappush(q,(H[n],n))
return d
x=b(0);y=b(N-1)
a=-1
for i in range(N):
if x[i]==-1 or y[i]==-1:
continue
a=max(a,x[i]+y[i]+1)
print(a)