#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 = 1e9 + 7;
int d[2][N];
vector<int> adj[N];
int arr[N];
int32_t main(){
//fileio();
fastio();
int n, m;
cin>>n>>m;
for (int i = 1; i <= n; i++){
cin>>arr[i];
}
for (int i = 1; i <= m; i++){
int u, v;
cin>>u>>v;
adj[u].pb(v);
adj[v].pb(u);
}
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]){
int dist = max(arr[j], dd + 1);
if (d[i][j] > dist){
d[i][j] = dist;
q.push({-dist, j});
}
}
}
root = n;
}
int ans = INF;
for (int i = 2; i <= n - 1; i++){
ans = min(ans, d[0][i] + d[1][i]);
//cout<<i<<sp<<d[0][i]<<sp<<d[1][i]<<endl;
}
if (d[0][n] == 0) ans = 0;
cout<<ans<<endl;
cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Incorrect |
55 ms |
19796 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Incorrect |
2 ms |
10588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Incorrect |
2 ms |
10588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Incorrect |
55 ms |
19796 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |