Submission #886678

#TimeUsernameProblemLanguageResultExecution timeMemory
886678fanwenAirplane (NOI23_airplane)C++17
100 / 100
291 ms24544 KiB
#include <bits/stdc++.h> using namespace std; #define MASK(x) (1LL << (x)) #define BIT(x, i) (((x) >> (i)) & 1) #define ALL(x) (x).begin(), (x).end() #define REP(i, n) for (int i = 0, _n = n; i < _n; ++i) #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i) #define FORE(i, a, b) for (int i = (a), _b = (b); i < _b; ++i) #define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } template <class A, class B> bool minimize(A &a, B b) { if (a > b) { a = b; return true; } return false; } template <class A, class B> bool maximize(A &a, B b) { if (a < b) { a = b; return true; } return false; } const int MAXN = 2e5 + 5; int N, M, a[MAXN], dpL[MAXN], dpR[MAXN]; vector <int> adj[MAXN]; void dijkstra(int s, int dp[]) { fill(dp + 1, dp + N + 1, 1e9); dp[s] = a[s]; priority_queue <pair <int, int>, vector <pair <int, int>>, greater_equal <pair <int, int>>> q; q.emplace(dp[s], s); while(q.size()) { auto [du, u] = q.top(); q.pop(); if(dp[u] != du) continue; for (auto v : adj[u]) if(minimize(dp[v], max(dp[u] + 1, a[v]))) { q.emplace(dp[v], v); } } } void you_make_it(void) { cin >> N >> M; FOR(i, 1, N) cin >> a[i]; while(M--) { int u, v; cin >> u >> v; adj[u].emplace_back(v); adj[v].emplace_back(u); } int res = 2e9; dijkstra(1, dpL); dijkstra(N, dpR); FOR(i, 1, N) { minimize(res, 2 * max(dpL[i], dpR[i])); } // FOR(i, 1, N) cout << dpL[i] << " \n"[i == N]; // FOR(i, 1, N) cout << dpR[i] << " \n"[i == N]; FOR(u, 1, N) for (auto v : adj[u]) { minimize(res, 2 * max(dpL[u], dpR[v]) + 1); } cout << res; } signed main() { #ifdef LOCAL freopen("TASK.inp", "r", stdin); freopen("TASK.out", "w", stdout); #endif file("airplane"); auto start_time = chrono::steady_clock::now(); cin.tie(0), cout.tie(0) -> sync_with_stdio(0); you_make_it(); auto end_time = chrono::steady_clock::now(); cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl; return (0 ^ 0); } // Dream it. Wish it. Do it.

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:13:57: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:66:4: note: in expansion of macro 'file'
   66 |    file("airplane");
      |    ^~~~
Main.cpp:13:90: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:66:4: note: in expansion of macro 'file'
   66 |    file("airplane");
      |    ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...