#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
const int mn=2e5+5;
const int mod=1e9+7;
int a[mn];
pii dp[mn];
vector<int> g[mn];
signed main(){
//freopen("","r",stdin);
//freopen("","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin>>n>>m;
int ans=1e18;
for (int i=1;i<=n;i++){
cin>>a[i];
dp[i]={1e18,1e18};
}
for (int i=1;i<=m;i++){
int u,v;
cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
}
dp[1]={0,0};
priority_queue<pair<pii,int>,vector<pair<pii,int>>,greater<pair<pii,int>>> pq;
pq.push({{0,0},1});
while (!pq.empty()){
int lb=pq.top().fi.fi-pq.top().fi.se;
int ub=pq.top().fi.se;
int id=pq.top().se;
pq.pop();
pii cur={lb+ub,ub};
if (dp[id]!=cur) continue;
for (int v:g[id]){
if (v==n) ans=min(ans,ub+lb);
else{
if (a[v]>ub){
int l=a[v];
int r=a[v];
if (l+r<dp[v].fi){
dp[v]={l+r,r};
pq.push({{l+r,r},v});
}
}
else{
int l=max(a[v],lb-1);
int r=ub+1;
if (l+r<dp[v].fi){
dp[v]={l+r,r};
pq.push({{l+r,r},v});
}
}
}
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4956 KB |
Output is correct |
2 |
Correct |
48 ms |
19272 KB |
Output is correct |
3 |
Correct |
48 ms |
19688 KB |
Output is correct |
4 |
Correct |
50 ms |
19796 KB |
Output is correct |
5 |
Correct |
63 ms |
20308 KB |
Output is correct |
6 |
Correct |
50 ms |
20308 KB |
Output is correct |
7 |
Correct |
50 ms |
20256 KB |
Output is correct |
8 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4956 KB |
Output is correct |
2 |
Correct |
48 ms |
19272 KB |
Output is correct |
3 |
Correct |
48 ms |
19688 KB |
Output is correct |
4 |
Correct |
50 ms |
19796 KB |
Output is correct |
5 |
Correct |
63 ms |
20308 KB |
Output is correct |
6 |
Correct |
50 ms |
20308 KB |
Output is correct |
7 |
Correct |
50 ms |
20256 KB |
Output is correct |
8 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |