#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define lastbit(i) __builtin_ctz(i)
#define pil pair<int,long long>
const int maxn=2e5+9;
const long long inf=1e15;
long long b[maxn];
vector<int>a[maxn];
int n;
struct cus{
int u;
long long val;
bool operator < (const cus &p)const {
return val>p.val;
}
};
vector<long long> cal(int s){
vector<long long>f(n+1);
vector<bool>vis(n+1);
for1(i,1,n)f[i]=inf;
f[s]=0;
priority_queue<cus>t;
t.push({s,0});
while (!t.empty()){
auto u=t.top();
t.pop();
if (vis[u.u])continue;
vis[u.u]=1;
for (auto v:a[u.u]){
if (f[v]>max(b[v],f[u.u]+1)){
f[v]=max(b[v],f[u.u]+1);
t.push({v,f[v]});
}
}
}
return f;
}
long long ans[maxn];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("temp.INP","r",stdin);
//freopen("temp.OUT","w",stdout);
int m;
cin>>n>>m;
for1(i,1,n)cin>>b[i];
for1(i,1,m){
int u,v;
cin>>u>>v;
a[u].pb(v);
a[v].pb(u);
}
vector<long long>tmp=cal(1);
for1(i,1,n){
ans[i]+=tmp[i];
//cout<<i<<" "<<tmp[i]<<'\n';
}
tmp=cal(n);
for1(i,1,n){
ans[i]+=tmp[i];
//cout<<i<<" "<<tmp[i]<<'\n';
}
long long vcl=inf;
for1(i,2,n-1)vcl=min(vcl,ans[i]);
cout<<vcl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Incorrect |
55 ms |
17616 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Incorrect |
55 ms |
17616 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |