Submission #676168

#TimeUsernameProblemLanguageResultExecution timeMemory
676168stevancvAesthetic (NOI20_aesthetic)C++14
100 / 100
495 ms41872 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 3e5 + 2; const ll linf = 1e18; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> u(m), v(m), w(m), suff(m); vector<vector<pair<int, int>>> g(n); for (int i = 0; i < m; i++) { cin >> u[i] >> v[i] >> w[i]; u[i] -= 1; v[i] -= 1; g[u[i]].push_back({v[i], i}); g[v[i]].push_back({u[i], i}); } for (int i = m - 2; i >= 0; i--) suff[i] = max(suff[i + 1], w[i + 1]); function<vector<ll>(int)> Dijk = [&] (int s) { vector<ll> dist(n, linf); priority_queue<pair<ll, int>> q; q.push({0, s}); while (!q.empty()) { auto s = q.top(); q.pop(); s.first *= -1; if (dist[s.second] <= s.first) continue; dist[s.second] = s.first; for (auto u : g[s.second]) { if (dist[u.first] == linf) q.push({-s.first - w[u.second], u.first}); } } return dist; }; vector<ll> a = Dijk(0); vector<ll> b = Dijk(n - 1); ll l = b[0], r = b[0] + suff[0]; auto Greater = [&] (ll x) { int is = 0; vector<int> dep(n, -1), mn(n); int tsz = 0; function<void(int, int)> Dfs = [&] (int s, int e) { dep[s] = mn[s] = tsz++; for (auto u : g[s]) { if (u.first == e) continue; ll y = min(a[s] + b[u.first], a[u.first] + b[s]) + w[u.second]; if (y > x) continue; if (dep[u.first] == -1) { Dfs(u.first, s); smin(mn[s], mn[u.first]); if (mn[u.first] > dep[s] && y + suff[u.second] > x && dep[n - 1] >= mn[u.first]) { is = 1; break; } } else smin(mn[s], dep[u.first]); } }; Dfs(0, -1); return is; }; while (l < r) { ll mid = l + r >> 1; if (Greater(mid)) l = mid + 1; else r = mid; } cout << l << en; return 0; }

Compilation message (stderr)

Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:69:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   69 |         ll mid = l + r >> 1;
      |                  ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...