#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int n, E;
int H[200005];
vector<int> disS, disE;
vector<int> adj[200005];
int vis[200005];
void dijkstra(int S, vector<int> &dis){
dis.resize(n+1);
fill(dis.begin(), dis.end(), 1e9);
fill(vis,vis+n+1,0);
priority_queue<ii, vector<ii>, greater<ii> > pq;
dis[S] = 0;
pq.push(ii(0,S));
while(not pq.empty()){
int u = pq.top().second; pq.pop();
if(vis[u]) continue;
vis[u] = true;
for(int v : adj[u]){
if(dis[v] > max(H[v], dis[u] + 1)){
dis[v] = max(H[v], dis[u] + 1);
pq.push(ii(dis[v],v));
}
}
}
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0); //fast input/output
cin >> n >> E;
for(int i = 1;i <= n;i++) cin >> H[i];
for(int i = 1;i <= E;i++){
int a, b; cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dijkstra(1, disS);
dijkstra(n, disE);
int ans = 1e9;
for(int u = 1;u <= n;u++){
//cerr << disS[u] << " " << disE[u] << '\n';
ans = min(ans, max(disS[u],disE[u])*2);
for(int v : adj[u]){
ans = min(ans, max(disS[u],disE[v])*2 + 1);
ans = min(ans, max(disS[v],disE[u])*2 + 1);
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
67 ms |
14396 KB |
Output is correct |
3 |
Correct |
72 ms |
14288 KB |
Output is correct |
4 |
Correct |
77 ms |
14312 KB |
Output is correct |
5 |
Correct |
88 ms |
14316 KB |
Output is correct |
6 |
Correct |
70 ms |
14392 KB |
Output is correct |
7 |
Correct |
69 ms |
14304 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
5 ms |
5076 KB |
Output is correct |
11 |
Correct |
4 ms |
5076 KB |
Output is correct |
12 |
Correct |
4 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
4 ms |
5076 KB |
Output is correct |
15 |
Correct |
5 ms |
5076 KB |
Output is correct |
16 |
Correct |
3 ms |
5076 KB |
Output is correct |
17 |
Correct |
4 ms |
5076 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5076 KB |
Output is correct |
10 |
Correct |
5 ms |
5076 KB |
Output is correct |
11 |
Correct |
4 ms |
5076 KB |
Output is correct |
12 |
Correct |
4 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
4 ms |
5076 KB |
Output is correct |
15 |
Correct |
5 ms |
5076 KB |
Output is correct |
16 |
Correct |
3 ms |
5076 KB |
Output is correct |
17 |
Correct |
4 ms |
5076 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
4 ms |
5088 KB |
Output is correct |
25 |
Correct |
3 ms |
5076 KB |
Output is correct |
26 |
Correct |
4 ms |
5076 KB |
Output is correct |
27 |
Correct |
4 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5076 KB |
Output is correct |
29 |
Correct |
4 ms |
5076 KB |
Output is correct |
30 |
Correct |
4 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
67 ms |
14396 KB |
Output is correct |
3 |
Correct |
72 ms |
14288 KB |
Output is correct |
4 |
Correct |
77 ms |
14312 KB |
Output is correct |
5 |
Correct |
88 ms |
14316 KB |
Output is correct |
6 |
Correct |
70 ms |
14392 KB |
Output is correct |
7 |
Correct |
69 ms |
14304 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
4 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5076 KB |
Output is correct |
16 |
Correct |
4 ms |
5076 KB |
Output is correct |
17 |
Correct |
3 ms |
5076 KB |
Output is correct |
18 |
Correct |
5 ms |
5076 KB |
Output is correct |
19 |
Correct |
4 ms |
5076 KB |
Output is correct |
20 |
Correct |
4 ms |
5076 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 KB |
Output is correct |
22 |
Correct |
4 ms |
5076 KB |
Output is correct |
23 |
Correct |
5 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
5076 KB |
Output is correct |
25 |
Correct |
4 ms |
5076 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
4 ms |
5076 KB |
Output is correct |
28 |
Correct |
3 ms |
5076 KB |
Output is correct |
29 |
Correct |
3 ms |
5076 KB |
Output is correct |
30 |
Correct |
3 ms |
5076 KB |
Output is correct |
31 |
Correct |
3 ms |
5076 KB |
Output is correct |
32 |
Correct |
4 ms |
5088 KB |
Output is correct |
33 |
Correct |
3 ms |
5076 KB |
Output is correct |
34 |
Correct |
4 ms |
5076 KB |
Output is correct |
35 |
Correct |
4 ms |
5076 KB |
Output is correct |
36 |
Correct |
4 ms |
5076 KB |
Output is correct |
37 |
Correct |
4 ms |
5076 KB |
Output is correct |
38 |
Correct |
4 ms |
5076 KB |
Output is correct |
39 |
Correct |
287 ms |
14476 KB |
Output is correct |
40 |
Correct |
154 ms |
14328 KB |
Output is correct |
41 |
Correct |
176 ms |
14472 KB |
Output is correct |
42 |
Correct |
120 ms |
14444 KB |
Output is correct |
43 |
Correct |
158 ms |
14444 KB |
Output is correct |
44 |
Correct |
161 ms |
14460 KB |
Output is correct |
45 |
Correct |
182 ms |
14376 KB |
Output is correct |
46 |
Correct |
180 ms |
14468 KB |
Output is correct |
47 |
Correct |
153 ms |
14460 KB |
Output is correct |
48 |
Correct |
163 ms |
14344 KB |
Output is correct |
49 |
Correct |
228 ms |
14496 KB |
Output is correct |
50 |
Correct |
237 ms |
14464 KB |
Output is correct |
51 |
Correct |
212 ms |
14468 KB |
Output is correct |
52 |
Correct |
290 ms |
15960 KB |
Output is correct |
53 |
Correct |
297 ms |
16036 KB |
Output is correct |
54 |
Correct |
281 ms |
16040 KB |
Output is correct |
55 |
Correct |
342 ms |
16060 KB |
Output is correct |
56 |
Correct |
497 ms |
18124 KB |
Output is correct |
57 |
Correct |
457 ms |
18144 KB |
Output is correct |
58 |
Correct |
448 ms |
18152 KB |
Output is correct |
59 |
Correct |
453 ms |
18216 KB |
Output is correct |
60 |
Correct |
400 ms |
18172 KB |
Output is correct |
61 |
Correct |
463 ms |
18176 KB |
Output is correct |
62 |
Correct |
392 ms |
18128 KB |
Output is correct |
63 |
Correct |
373 ms |
18116 KB |
Output is correct |
64 |
Correct |
390 ms |
18156 KB |
Output is correct |
65 |
Correct |
365 ms |
18116 KB |
Output is correct |
66 |
Correct |
378 ms |
18192 KB |
Output is correct |
67 |
Correct |
366 ms |
18144 KB |
Output is correct |