結果

問題 No.3385 Up Down Hiking (C++)
コンテスト
ユーザー Rho
提出日時 2025-11-22 00:35:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 643 bytes
コンパイル時間 1,777 ms
コンパイル使用メモリ 201,120 KB
実行使用メモリ 13,732 KB
最終ジャッジ日時 2025-11-22 12:40:04
合計ジャッジ時間 10,271 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 25 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

vector<int>G[200000];
int h[200000],d1[200000],d2[200000];
void b(int s,int* d){
	queue<int>q;
	d[s]=0;
	q.push(s);
	while(q.size()){
		int v=q.front();
		q.pop();
		for(auto e:G[v]){
			if(h[v]<h[e]){
				q.push(e);
				d[e]=d[v]+1;
			}
		}
	}
}

int main(){
	int n,m;
	cin>>n>>m;
	rep(i,n)cin>>h[i];
	rep(i,m){
		int a,b;
		cin>>a>>b;
		G[--a].push_back(--b);
		G[b].push_back(a);
	}
	fill(d1,d1+n,-1e9);
	fill(d2,d2+n,-1e9);
	b(0,d1);b(n-1,d2);
	int ans=-1e9;
	rep(i,n){
		ans=max(ans,d1[i]+d2[i]);
	}
	if(ans<0)cout<<-1<<endl;
	else cout<<ans+1<<endl;

}
0