Submission #1128665

#TimeUsernameProblemLanguageResultExecution timeMemory
1128665pemguimnAirplane (NOI23_airplane)C++17
100 / 100
399 ms25708 KiB
#include <bits/stdc++.h> #define int long long #define pii pair<int, int> using namespace std; const int N = 2e5 + 5, INF = 1e18 + 5; int n, m, a[N]; vector<int> adj[N]; vector<int> go(int s){ vector<int> d(n + 1, INF); d[s] = 0; priority_queue<pii> pq; pq.push({-d[s], s}); while(!pq.empty()){ pii cur = pq.top(); pq.pop(); if(-cur.first != d[cur.second]) continue; int w = -cur.first, i = cur.second; for(int x : adj[i]){ int nww = max(w + 1, a[x]); if(d[x] > nww){ d[x] = nww; pq.push({-d[x], x}); } } } return d; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for(int i = 1; i <= n; i++){ cin >> a[i]; } for(int i = 1; i <= m; i++){ int x, y; cin >> x >> y; adj[x].push_back(y), adj[y].push_back(x); } vector<int> d1 = go(1); vector<int> dn = go(n); int ans = INF; for(int i = 1; i <= n; i++){ ans = min(ans, max(d1[i], dn[i]) * 2); for(int x : adj[i]){ ans = min(ans, max(d1[i], dn[x]) * 2 + 1); ans = min(ans, max(d1[x], dn[i]) * 2 + 1); } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...