/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
const long int base = 1e18;
int main()
{
int n,m;
cin>>n>>m;
long long int a[n+1];
long long int h[n+1];
for(int i =1;i<=n;i++){
cin>>a[i];
h[i]=base;
}
vector<int> arr[n+1];
for(int i =0;i<m;i++){
int a,b;
cin>>a>>b;
arr[a].push_back(b);
arr[b].push_back(a);
}
priority_queue<vector<long long int> , vector<vector<long long int>>, greater<vector<long long int>> > q;
h[1]=0;
q.push({0,1,0});
while(!q.empty()){
int u = q.top()[1];
long long int d = q.top()[0];
q.pop();
if(d!=h[u])continue;
for(int v : arr[u]){
// cout<<v<<endl;
long long int height = q.top()[2];
long long int ans = d+1;
if(a[v]>height){
ans+=(a[v]-height-1);
height=a[v];
}
if(v==n)ans+=max(a[u],a[v]);
if(ans>=h[v])continue;
h[v]=ans;
q.push({ans,v,height});
}
}
cout<<h[n]-1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
134 ms |
14348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
134 ms |
14348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |