제출 #886213

#제출 시각아이디문제언어결과실행 시간메모리
886213vjudge1Airplane (NOI23_airplane)C++17
41 / 100
1086 ms22440 KiB
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define sp " "
#define endl "\n"
#define pii pair<int, int>
#define st first
#define nd second
#define pb push_back
#define N 300005
#define int long long

const int INF = 2e18 + 7;

int d[2][N];
vector<int> adj[N];
int arr[N], maks[2][N];

int32_t main(){
	//fileio();
	fastio();

	int n, m;
	cin>>n>>m;
	vector<int> v;
	for (int i = 1; i <= n; i++){
		cin>>arr[i];
		v.pb(arr[i]);
	}
	sort(v.begin(), v.end());

	for (int i = 1; i <= m; i++){
		int u, v;
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	int ans = INF;
	for (auto K : v){
		int root = 1;
		for (int i = 0; i < 2; i++){
			priority_queue<pii> q;
			q.push({0, root});
			for (int j = 1; j <= n; j++){
				d[i][j] = INF;
			}
			d[i][root] = 0;
			while(!q.empty()){
				int top = q.top().nd;
				int dd = -q.top().st;
				q.pop();
				for (auto j : adj[top]){
					if (arr[j] > K) continue;
					int dist = max(arr[j], dd + 1);
					if (d[i][j] > dist){
						d[i][j] = dist;
						q.push({-dist, j});
					}
				}
			}
			root = n;
		}

		for (int i = 1; i <= n; i++){
			if (arr[i] == K) ans = min(ans, d[0][i] + d[1][i]);
		}
	}
		
	cout<<ans<<endl;
	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...