#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
int main(){
int n,m;cin>>n>>m;
vector<int> val(n);
for (int i = 0; i < n; ++i)
{
cin>>val[i];
}
vector<vector<int>> arr(n);
for (int i = 0; i < m; i++){
int u,v;cin>>u>>v;
arr[u-1].push_back(v-1);
arr[v-1].push_back(u-1);
}
vector<pair<int,int>> dp(n,{INF,INF});
priority_queue<array<int,3>,vector<array<int,3>>,greater<array<int,3>>> pq;
pq.push({0,0,0});
while (pq.size()){
int node = pq.top()[2];
int w = pq.top()[0];
int dist = pq.top()[1];
pq.pop();
if (dp[node].first<w+dist) continue;
if (dp[node].first==w+dist && dp[node].second<dist) continue;
dp[node]={w+dist,dist};
for (int i = 0; i < arr[node].size(); i++){
pq.push({max(w,val[arr[node][i]]),dist+1,arr[node][i]});
}
}
cout<<dp[n-1].first<<endl;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:28:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (int i = 0; i < arr[node].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
152 ms |
13488 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 |
Incorrect |
0 ms |
348 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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
152 ms |
13488 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |