Submission #891931

# Submission time Handle Problem Language Result Execution time Memory
891931 2023-12-24T13:15:04 Z vjudge1 Airplane (NOI23_airplane) C++17
100 / 100
212 ms 20524 KB
#include<bits/stdc++.h>

using namespace std;

#define read() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define day() time_t now = time(0);char* x = ctime(&now);cerr<<"Right Now Is : "<<x<<"\n"

#define ii pair<int,int>
#define X first
#define Y second 

const long long MAX = (int)2e5 + 5;
const long long INF = (int)1e9;
const long long MOD = (int)1e9 + 7;

int n,m;
int step[MAX],fx[MAX];
vector<int> adj[MAX];
int a[MAX];

priority_queue<ii,vector<ii>,greater<ii>> pq;

signed main(){
	
	read();
	
	cin >> n >> m;
	
	for(int i = 1;i <= n;i++)cin >> a[i];
	
	for(int i = 1,u,v;i <= m;i++){
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	
	memset(step,0x3f,sizeof step);
	memset(fx,0x3f,sizeof fx);
	
	pq.push({0,1});
	step[1] = 0;
	
	while(!pq.empty()){
		int u = pq.top().Y;
		int d = pq.top().X;
		
		pq.pop();
		
		if(d != step[u])continue;
		
		for(auto v : adj[u]){
			if(step[v] > max(step[u] + 1,a[v])){
				step[v] = max(step[u] + 1,a[v]);
				pq.push({step[v],v});
			}
		}
	}
	
	pq.push({0,n});
	fx[n] = 0;
	
	while(!pq.empty()){
		int u = pq.top().Y;
		int d = pq.top().X;
		
		pq.pop();
		
		if(d != fx[u])continue;
		
		for(auto v : adj[u]){
			if(fx[v] > max(fx[u] + 1,a[v])){
				fx[v] = max(fx[u] + 1,a[v]);
				pq.push({fx[v],v});
			}
		}
	}
	
	int res = INF;
	for(int i = 1;i <= n;i++){
		res = min(res,2 * max(step[i],fx[i]));
	}
	
	for(int i = 1;i <= n;i++){
		for(auto v : adj[i]){
			res = min(res,2 * max(step[i],fx[v]) + 1);
		}
	}
	
	
	cout << res;
	
	
}













# Verdict Execution time Memory Grader output
1 Correct 2 ms 7256 KB Output is correct
2 Correct 57 ms 13668 KB Output is correct
3 Correct 59 ms 15692 KB Output is correct
4 Correct 62 ms 15676 KB Output is correct
5 Correct 61 ms 16008 KB Output is correct
6 Correct 77 ms 15952 KB Output is correct
7 Correct 62 ms 15964 KB Output is correct
8 Correct 1 ms 7256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 7260 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 1 ms 7260 KB Output is correct
4 Correct 1 ms 7260 KB Output is correct
5 Correct 1 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 3 ms 7352 KB Output is correct
9 Correct 2 ms 7256 KB Output is correct
10 Correct 2 ms 7264 KB Output is correct
11 Correct 2 ms 7260 KB Output is correct
12 Correct 3 ms 7260 KB Output is correct
13 Correct 3 ms 7264 KB Output is correct
14 Correct 3 ms 7260 KB Output is correct
15 Correct 3 ms 7400 KB Output is correct
16 Correct 3 ms 7260 KB Output is correct
17 Correct 3 ms 7260 KB Output is correct
18 Correct 1 ms 7128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 7260 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 1 ms 7260 KB Output is correct
4 Correct 1 ms 7260 KB Output is correct
5 Correct 1 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 3 ms 7352 KB Output is correct
9 Correct 2 ms 7256 KB Output is correct
10 Correct 2 ms 7264 KB Output is correct
11 Correct 2 ms 7260 KB Output is correct
12 Correct 3 ms 7260 KB Output is correct
13 Correct 3 ms 7264 KB Output is correct
14 Correct 3 ms 7260 KB Output is correct
15 Correct 3 ms 7400 KB Output is correct
16 Correct 3 ms 7260 KB Output is correct
17 Correct 3 ms 7260 KB Output is correct
18 Correct 1 ms 7128 KB Output is correct
19 Correct 3 ms 7256 KB Output is correct
20 Correct 2 ms 7260 KB Output is correct
21 Correct 2 ms 7260 KB Output is correct
22 Correct 2 ms 7256 KB Output is correct
23 Correct 2 ms 7256 KB Output is correct
24 Correct 2 ms 7256 KB Output is correct
25 Correct 3 ms 7260 KB Output is correct
26 Correct 3 ms 7260 KB Output is correct
27 Correct 3 ms 7260 KB Output is correct
28 Correct 3 ms 7260 KB Output is correct
29 Correct 3 ms 7396 KB Output is correct
30 Correct 3 ms 7256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7256 KB Output is correct
2 Correct 57 ms 13668 KB Output is correct
3 Correct 59 ms 15692 KB Output is correct
4 Correct 62 ms 15676 KB Output is correct
5 Correct 61 ms 16008 KB Output is correct
6 Correct 77 ms 15952 KB Output is correct
7 Correct 62 ms 15964 KB Output is correct
8 Correct 1 ms 7256 KB Output is correct
9 Correct 1 ms 7260 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 1 ms 7260 KB Output is correct
12 Correct 1 ms 7260 KB Output is correct
13 Correct 1 ms 7260 KB Output is correct
14 Correct 2 ms 7260 KB Output is correct
15 Correct 2 ms 7260 KB Output is correct
16 Correct 3 ms 7352 KB Output is correct
17 Correct 2 ms 7256 KB Output is correct
18 Correct 2 ms 7264 KB Output is correct
19 Correct 2 ms 7260 KB Output is correct
20 Correct 3 ms 7260 KB Output is correct
21 Correct 3 ms 7264 KB Output is correct
22 Correct 3 ms 7260 KB Output is correct
23 Correct 3 ms 7400 KB Output is correct
24 Correct 3 ms 7260 KB Output is correct
25 Correct 3 ms 7260 KB Output is correct
26 Correct 1 ms 7128 KB Output is correct
27 Correct 3 ms 7256 KB Output is correct
28 Correct 2 ms 7260 KB Output is correct
29 Correct 2 ms 7260 KB Output is correct
30 Correct 2 ms 7256 KB Output is correct
31 Correct 2 ms 7256 KB Output is correct
32 Correct 2 ms 7256 KB Output is correct
33 Correct 3 ms 7260 KB Output is correct
34 Correct 3 ms 7260 KB Output is correct
35 Correct 3 ms 7260 KB Output is correct
36 Correct 3 ms 7260 KB Output is correct
37 Correct 3 ms 7396 KB Output is correct
38 Correct 3 ms 7256 KB Output is correct
39 Correct 113 ms 15860 KB Output is correct
40 Correct 82 ms 15696 KB Output is correct
41 Correct 83 ms 15700 KB Output is correct
42 Correct 84 ms 15832 KB Output is correct
43 Correct 84 ms 15704 KB Output is correct
44 Correct 84 ms 15840 KB Output is correct
45 Correct 88 ms 15700 KB Output is correct
46 Correct 91 ms 15844 KB Output is correct
47 Correct 88 ms 15840 KB Output is correct
48 Correct 87 ms 15668 KB Output is correct
49 Correct 130 ms 16132 KB Output is correct
50 Correct 105 ms 15976 KB Output is correct
51 Correct 108 ms 16104 KB Output is correct
52 Correct 157 ms 18128 KB Output is correct
53 Correct 151 ms 17116 KB Output is correct
54 Correct 145 ms 17484 KB Output is correct
55 Correct 165 ms 17616 KB Output is correct
56 Correct 209 ms 20088 KB Output is correct
57 Correct 211 ms 19916 KB Output is correct
58 Correct 203 ms 20440 KB Output is correct
59 Correct 207 ms 20524 KB Output is correct
60 Correct 193 ms 20428 KB Output is correct
61 Correct 212 ms 20160 KB Output is correct
62 Correct 175 ms 19912 KB Output is correct
63 Correct 183 ms 19912 KB Output is correct
64 Correct 182 ms 19912 KB Output is correct
65 Correct 182 ms 19920 KB Output is correct
66 Correct 198 ms 19940 KB Output is correct
67 Correct 207 ms 19928 KB Output is correct