Submission #1279474

#TimeUsernameProblemLanguageResultExecution timeMemory
1279474AbdullahIshfaqAirplane (NOI23_airplane)C++20
100 / 100
197 ms21508 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define MOD 998244353 const int N = 200005; ll n, h[N]; vector<int> g[N]; vector<ll> dijkstra(ll src) { vector<ll> dist(n + 1, 2e18); priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq; dist[src] = 0; pq.push({0, src}); while (!pq.empty()) { auto [w, u] = pq.top(); pq.pop(); if (w > dist[u]) { continue; } for (auto i : g[u]) { if (max(h[i], w + 1) < dist[i]) { dist[i] = max(h[i], w + 1); pq.push({dist[i], i}); } } } return dist; } void solve() { ll m, u, v, ans = 2e18; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> h[i]; } for (int i = 0; i < m; i++) { cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } vector<ll> d1 = dijkstra(1), dn = dijkstra(n); for (int i = 1; i <= n; i++) { ans = min(ans, max(d1[i], dn[i]) * 2); for (auto j : g[i]) { ans = min(ans, max(d1[i], dn[j]) * 2 + 1); } } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tests = 1; // cin >> tests; for (int i = 1; i <= tests; i++) { solve(); } 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...