#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();
w-=dist;
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,dist+1,arr[node][i]});
}
}
cout<<dp[n-1].first<<endl;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:29:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i = 0; i < arr[node].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
136 ms |
13684 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
136 ms |
13684 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |