結果

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

ソースコード

diff #
raw source code

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

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

}
0