結果

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

ソースコード

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]&&d[e]<0){
				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