Submission #1169780

#TimeUsernameProblemLanguageResultExecution timeMemory
1169780ThanhsAirplane (NOI23_airplane)C++20
0 / 100
40 ms15944 KiB
#include <bits/stdc++.h> using namespace std; #define name "TENBAI" #define fi first #define se second #define int long long #define endl '\n' #define setmin(x, y) x = min((x), (y)) #define setmax(x, y) x = max((x), (y)) #define sqr(x) ((x) * (x)) mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count()); int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);} const int NM = 2e5 + 5; const int inf = 1e18; vector<int> g[NM]; int n, m, a[NM], ans; void calc(int s, vector<int>& d) { priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq; d.resize(n + 1, inf); d[s] = 0; pq.push({0, s}); while (pq.size()) { int w = pq.top().fi, u = pq.top().se; pq.pop(); if (d[u] != w) continue; queue<int> st; st.push(u); while (st.size()) { int U = st.front(); st.pop(); for (auto v : g[U]) { if (a[u] >= a[v] && d[v] > d[U] + 1) { d[v] = d[U] + 1; st.push(v); } else if (a[u] < a[v] && d[v] > max(d[U] + 1, w + a[v] - a[u])) { d[v] = max(d[U] + 1, w + a[v] - a[u]); pq.push({d[v], v}); } } } } } void solve() { 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; g[u].push_back(v); g[v].push_back(u); } vector<int> d1, d2; calc(1, d1); calc(n, d2); ans = inf; for (int i = 2; i < n; i++) setmin(ans, d1[i] + d2[i]); cout << ans << endl; } signed main() { if (fopen("in.txt", "r")) { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } else if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int tc = 1; // cin >> tc; while (tc--) solve(); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen("in.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen("out.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |         freopen(name".out", "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...