結果

問題 No.3386 Up Down Hiking (Python)
コンテスト
ユーザー miya145592
提出日時 2025-11-22 14:42:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 500 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 82,704 KB
実行使用メモリ 99,916 KB
最終ジャッジ日時 2025-11-22 14:42:28
合計ジャッジ時間 10,512 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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]*N;s=[0]*N;d[v]=0;q=[(H[v],v)]
 while q:
  _,v=heapq.heappop(q)
  if s[v]==1:continue
  s[v]=1
  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)
0