#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int main(){
int n, m;
cin >> n >> m;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
vector<vector<int>> G(n);
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
--a, --b;
G[a].pb(b);
G[b].pb(a);
}
// time, minalt, v
priority_queue<array<int, 3>, vector<array<int, 3>>, greater<array<int, 3>>> q;
q.push({0, 0, 0});
vector<bool> vis(n);
vis[0] = 1;
int ans = INT_MAX;
while(!q.empty()){
auto [time, minalt, u] = q.top(); q.pop();
// cout << u << ' ' <<
for(int v : G[u]){
if(vis[v]) continue;
if(v == n-1){
ans = min(ans, time + minalt + (minalt == 0));
} else if(time < a[v] - 1){
vis[v] = 1;
q.push({a[v], a[v], v});
} else{
vis[v] = 1;
q.push({time+1, max(max(minalt-1, a[v]), 0), v});
}
}
}
cout << ans << endl;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:33:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
33 | auto [time, minalt, u] = q.top(); q.pop();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
130 ms |
11996 KB |
Output is correct |
3 |
Correct |
138 ms |
11972 KB |
Output is correct |
4 |
Correct |
160 ms |
12212 KB |
Output is correct |
5 |
Correct |
150 ms |
12112 KB |
Output is correct |
6 |
Correct |
150 ms |
11960 KB |
Output is correct |
7 |
Correct |
151 ms |
12232 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
516 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
604 KB |
Output is correct |
17 |
Incorrect |
2 ms |
544 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
516 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
604 KB |
Output is correct |
17 |
Incorrect |
2 ms |
544 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
130 ms |
11996 KB |
Output is correct |
3 |
Correct |
138 ms |
11972 KB |
Output is correct |
4 |
Correct |
160 ms |
12212 KB |
Output is correct |
5 |
Correct |
150 ms |
12112 KB |
Output is correct |
6 |
Correct |
150 ms |
11960 KB |
Output is correct |
7 |
Correct |
151 ms |
12232 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
516 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
4 ms |
604 KB |
Output is correct |
25 |
Incorrect |
2 ms |
544 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |