Submission #1102372

#TimeUsernameProblemLanguageResultExecution timeMemory
1102372tuannmAirplane (NOI23_airplane)C++17
0 / 100
48 ms15092 KiB
#include<bits/stdc++.h> #define ii pair<int, int> #define ll pair<long long, long long> #define fi first #define se second #define pb push_back using namespace std; const int mod[2] = {1000000007, 998244353}; const int N = 2e5 + 1; const string NAME = ""; int n, m, a[N]; long long d[2][N]; vector<int> adj[N]; void inp(){ cin >> n >> m; for(int i = 1; i <= n; ++i) cin >> a[i]; for(int i = 1; i <= m; ++i){ int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } } void solve(){ priority_queue<pair<long long, int>> pq; for(int i = 1; i <= n; ++i) d[0][i] = d[1][i] = 1e16; d[0][1] = d[1][n] = 0; pq.push({0, 1}); while(!pq.empty()){ auto [dis, u] = pq.top(); pq.pop(); dis = -dis; if(dis != d[0][u]) continue; for(int v : adj[u]){ if(d[0][v] > max(d[0][u] + 1, 1LL * a[v])){ d[0][v] = max(d[0][u] + 1, 1LL * a[v]); pq.push({-d[0][v], v}); } } } pq.push({0, n}); while(!pq.empty()){ auto [dis, u] = pq.top(); pq.pop(); dis = -dis; if(dis != d[1][u]) continue; for(int v : adj[u]){ if(d[1][v] > max(d[1][u] + 1, 1LL * a[v])){ d[1][v] = max(d[1][u] + 1, 1LL * a[v]); pq.push({-d[1][v], v}); } } } long long ans = 1e16; for(int i = 2; i < n; ++i) ans = min(ans, d[0][i] + d[1][i]); cout << ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen((NAME + ".inp").c_str(), "r")){ freopen((NAME + ".inp").c_str(), "r", stdin); freopen((NAME + ".out").c_str(), "w", stdout); } inp(); solve(); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen((NAME + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen((NAME + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...