#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N=2e5+5;
const int INF=INT_MAX/2;
int n,m;
int a[N];
vector<int> adj[N];
int dist1[N],dist2[N];
int ans=INF;
void dijkstra(int st,int *dist){
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
for(int i=1;i<=n;i++)dist[i]=INF;
dist[st]=0;
pq.emplace(0,st);
while(!pq.empty()){
auto [d,u]=pq.top();
pq.pop();
if(d>dist[u])continue;
for(auto v:adj[u]){
int nd=max(d+1,a[v]);
if(nd<dist[v]){
dist[v]=nd;
pq.emplace(nd,v);
}
}
}
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> m;
for(int i=1;i<=n;i++)cin >> a[i];
for(int i=0;i<m;i++){
int u,v;
cin >> u >> v;
adj[u].emplace_back(v);
adj[v].emplace_back(u);
}
dijkstra(1,dist1);
dijkstra(n,dist2);
for(int i=1;i<=n;i++){
ans=min(ans,max(dist1[i],dist2[i])*2);
}
for(int u=1;u<=n;u++){
for(auto v:adj[u]){
ans=min(ans,max(dist1[u],dist2[v])*2+1);
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
48 ms |
13564 KB |
Output is correct |
3 |
Correct |
51 ms |
16712 KB |
Output is correct |
4 |
Correct |
55 ms |
16612 KB |
Output is correct |
5 |
Correct |
56 ms |
17176 KB |
Output is correct |
6 |
Correct |
55 ms |
17224 KB |
Output is correct |
7 |
Correct |
55 ms |
17344 KB |
Output is correct |
8 |
Correct |
2 ms |
6648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6648 KB |
Output is correct |
2 |
Correct |
2 ms |
6480 KB |
Output is correct |
3 |
Correct |
1 ms |
6480 KB |
Output is correct |
4 |
Correct |
1 ms |
6480 KB |
Output is correct |
5 |
Correct |
1 ms |
6480 KB |
Output is correct |
6 |
Correct |
2 ms |
6480 KB |
Output is correct |
7 |
Correct |
2 ms |
6480 KB |
Output is correct |
8 |
Correct |
2 ms |
6480 KB |
Output is correct |
9 |
Correct |
2 ms |
6480 KB |
Output is correct |
10 |
Correct |
2 ms |
6480 KB |
Output is correct |
11 |
Correct |
2 ms |
6480 KB |
Output is correct |
12 |
Correct |
2 ms |
6480 KB |
Output is correct |
13 |
Correct |
3 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
6736 KB |
Output is correct |
15 |
Correct |
3 ms |
6744 KB |
Output is correct |
16 |
Correct |
3 ms |
6736 KB |
Output is correct |
17 |
Correct |
3 ms |
6736 KB |
Output is correct |
18 |
Correct |
1 ms |
6480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6648 KB |
Output is correct |
2 |
Correct |
2 ms |
6480 KB |
Output is correct |
3 |
Correct |
1 ms |
6480 KB |
Output is correct |
4 |
Correct |
1 ms |
6480 KB |
Output is correct |
5 |
Correct |
1 ms |
6480 KB |
Output is correct |
6 |
Correct |
2 ms |
6480 KB |
Output is correct |
7 |
Correct |
2 ms |
6480 KB |
Output is correct |
8 |
Correct |
2 ms |
6480 KB |
Output is correct |
9 |
Correct |
2 ms |
6480 KB |
Output is correct |
10 |
Correct |
2 ms |
6480 KB |
Output is correct |
11 |
Correct |
2 ms |
6480 KB |
Output is correct |
12 |
Correct |
2 ms |
6480 KB |
Output is correct |
13 |
Correct |
3 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
6736 KB |
Output is correct |
15 |
Correct |
3 ms |
6744 KB |
Output is correct |
16 |
Correct |
3 ms |
6736 KB |
Output is correct |
17 |
Correct |
3 ms |
6736 KB |
Output is correct |
18 |
Correct |
1 ms |
6480 KB |
Output is correct |
19 |
Correct |
3 ms |
6736 KB |
Output is correct |
20 |
Correct |
2 ms |
6480 KB |
Output is correct |
21 |
Correct |
2 ms |
6736 KB |
Output is correct |
22 |
Correct |
2 ms |
6736 KB |
Output is correct |
23 |
Correct |
3 ms |
6632 KB |
Output is correct |
24 |
Correct |
3 ms |
6480 KB |
Output is correct |
25 |
Correct |
2 ms |
6736 KB |
Output is correct |
26 |
Correct |
3 ms |
6736 KB |
Output is correct |
27 |
Correct |
3 ms |
6736 KB |
Output is correct |
28 |
Correct |
3 ms |
6736 KB |
Output is correct |
29 |
Correct |
3 ms |
6592 KB |
Output is correct |
30 |
Correct |
3 ms |
6736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
48 ms |
13564 KB |
Output is correct |
3 |
Correct |
51 ms |
16712 KB |
Output is correct |
4 |
Correct |
55 ms |
16612 KB |
Output is correct |
5 |
Correct |
56 ms |
17176 KB |
Output is correct |
6 |
Correct |
55 ms |
17224 KB |
Output is correct |
7 |
Correct |
55 ms |
17344 KB |
Output is correct |
8 |
Correct |
2 ms |
6648 KB |
Output is correct |
9 |
Correct |
2 ms |
6648 KB |
Output is correct |
10 |
Correct |
2 ms |
6480 KB |
Output is correct |
11 |
Correct |
1 ms |
6480 KB |
Output is correct |
12 |
Correct |
1 ms |
6480 KB |
Output is correct |
13 |
Correct |
1 ms |
6480 KB |
Output is correct |
14 |
Correct |
2 ms |
6480 KB |
Output is correct |
15 |
Correct |
2 ms |
6480 KB |
Output is correct |
16 |
Correct |
2 ms |
6480 KB |
Output is correct |
17 |
Correct |
2 ms |
6480 KB |
Output is correct |
18 |
Correct |
2 ms |
6480 KB |
Output is correct |
19 |
Correct |
2 ms |
6480 KB |
Output is correct |
20 |
Correct |
2 ms |
6480 KB |
Output is correct |
21 |
Correct |
3 ms |
6492 KB |
Output is correct |
22 |
Correct |
2 ms |
6736 KB |
Output is correct |
23 |
Correct |
3 ms |
6744 KB |
Output is correct |
24 |
Correct |
3 ms |
6736 KB |
Output is correct |
25 |
Correct |
3 ms |
6736 KB |
Output is correct |
26 |
Correct |
1 ms |
6480 KB |
Output is correct |
27 |
Correct |
3 ms |
6736 KB |
Output is correct |
28 |
Correct |
2 ms |
6480 KB |
Output is correct |
29 |
Correct |
2 ms |
6736 KB |
Output is correct |
30 |
Correct |
2 ms |
6736 KB |
Output is correct |
31 |
Correct |
3 ms |
6632 KB |
Output is correct |
32 |
Correct |
3 ms |
6480 KB |
Output is correct |
33 |
Correct |
2 ms |
6736 KB |
Output is correct |
34 |
Correct |
3 ms |
6736 KB |
Output is correct |
35 |
Correct |
3 ms |
6736 KB |
Output is correct |
36 |
Correct |
3 ms |
6736 KB |
Output is correct |
37 |
Correct |
3 ms |
6592 KB |
Output is correct |
38 |
Correct |
3 ms |
6736 KB |
Output is correct |
39 |
Correct |
119 ms |
17180 KB |
Output is correct |
40 |
Correct |
83 ms |
16716 KB |
Output is correct |
41 |
Correct |
86 ms |
16688 KB |
Output is correct |
42 |
Correct |
94 ms |
16660 KB |
Output is correct |
43 |
Correct |
76 ms |
16860 KB |
Output is correct |
44 |
Correct |
83 ms |
16668 KB |
Output is correct |
45 |
Correct |
88 ms |
16728 KB |
Output is correct |
46 |
Correct |
87 ms |
16716 KB |
Output is correct |
47 |
Correct |
161 ms |
16792 KB |
Output is correct |
48 |
Correct |
96 ms |
16656 KB |
Output is correct |
49 |
Correct |
157 ms |
17236 KB |
Output is correct |
50 |
Correct |
95 ms |
17092 KB |
Output is correct |
51 |
Correct |
108 ms |
16968 KB |
Output is correct |
52 |
Correct |
152 ms |
19860 KB |
Output is correct |
53 |
Correct |
138 ms |
18780 KB |
Output is correct |
54 |
Correct |
134 ms |
19192 KB |
Output is correct |
55 |
Correct |
161 ms |
19180 KB |
Output is correct |
56 |
Correct |
191 ms |
22080 KB |
Output is correct |
57 |
Correct |
235 ms |
21932 KB |
Output is correct |
58 |
Correct |
236 ms |
22844 KB |
Output is correct |
59 |
Correct |
208 ms |
22732 KB |
Output is correct |
60 |
Correct |
169 ms |
24132 KB |
Output is correct |
61 |
Correct |
205 ms |
22588 KB |
Output is correct |
62 |
Correct |
189 ms |
22200 KB |
Output is correct |
63 |
Correct |
178 ms |
22092 KB |
Output is correct |
64 |
Correct |
169 ms |
22084 KB |
Output is correct |
65 |
Correct |
163 ms |
22108 KB |
Output is correct |
66 |
Correct |
209 ms |
22084 KB |
Output is correct |
67 |
Correct |
196 ms |
22076 KB |
Output is correct |