Submission #970946

#TimeUsernameProblemLanguageResultExecution timeMemory
970946CSQ31Airplane (NOI23_airplane)C++17
100 / 100
276 ms26976 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define sz(a) (int)(a.size()) #define all(a) a.begin(),a.end() #define lb lower_bound #define ub upper_bound #define owo ios_base::sync_with_stdio(0);cin.tie(0); #define MOD (ll)(998244353) #define INF (ll)(1e18) #define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr) #define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\ debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC)) typedef long long int ll; typedef long double ld; typedef pair<ll,ll> PII; typedef pair<int,int> pii; typedef vector<vector<int>> vii; typedef vector<vector<ll>> VII; const int MAXN = 2e5+5; vector<int>adj[MAXN]; ll d0[MAXN],d1[MAXN],a[MAXN]; int main() { owo int n,m; cin>>n>>m; for(int i=0;i<n;i++)cin>>a[i]; for(int i=0;i<m;i++){ int v,u; cin>>v>>u; v--; u--; adj[v].pb(u); adj[u].pb(v); } for(int i=0;i<n;i++)d0[i] = d1[i] = 1e18; d0[0] = 0; priority_queue<PII,vector<PII>,greater<PII>>pq; pq.push({0,0}); while(!pq.empty()){ ll d = pq.top().fi; int v = pq.top().se; pq.pop(); if(d != d0[v])continue; for(int x:adj[v]){ if(d+1 <= a[x] && a[x] < d0[x]){ d0[x] = a[x]; pq.push({a[x],x}); }else if(d+1 > a[x] && d+1 < d0[x]){ d0[x] = d+1; pq.push({d+1,x}); } } } d1[n-1] = 0; pq.push({0,n-1}); while(!pq.empty()){ ll d = pq.top().fi; int v = pq.top().se; pq.pop(); if(d != d1[v])continue; for(int x:adj[v]){ if(d+1 <= a[x] && a[x] < d1[x]){ d1[x] = a[x]; pq.push({a[x],x}); }else if(d+1 > a[x] && d+1 < d1[x]){ d1[x] = d+1; pq.push({d+1,x}); } } } ll ans = INF; for(int i=0;i<n;i++){ ans = min(ans,2*max(d0[i],d1[i])); for(int x:adj[i]){ ans = min(ans,2*max(d0[i],d1[x])+1); } } cout<<ans<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...