Submission #1065187

#TimeUsernameProblemLanguageResultExecution timeMemory
1065187Gromp15Closing Time (IOI23_closing)C++17
0 / 100
82 ms51764 KiB
#include <bits/stdc++.h> #include "closing.h" #define ar array #define ll long long #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() using namespace std; template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const ll INF = 1e18; int max_score(int n, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W) { vector<vector<ar<int, 2>>> adj(n+1); for (int i = 0; i < n-1; i++) { adj[U[i]].push_back({V[i], W[i]}); adj[V[i]].push_back({U[i], W[i]}); } vector<vector<ll>> d(2, vector<ll>(n+1, INF)); vector<int> p(n+1, -1); auto dfs = [&](auto&& s, int v, vector<ll>& dist) -> void { for (auto [u, w] : adj[v]) if (u != p[v]) { p[u] = v, dist[u] = dist[v] + w; s(s, u, dist); } }; d[0][X] = 0, d[1][Y] = 0; dfs(dfs, X, d[0]); fill(all(p), -1); dfs(dfs, Y, d[1]); vector<int> pth; for (int x = X; x != Y; x = p[x]) pth.emplace_back(x); pth.emplace_back(Y); const int N = sz(pth); vector<bool> inpath(N+1); for (int x : pth) inpath[x] = 1; int ans = 0; /* cout << "Pth\n"; for (int x : pth) cout << x << " "; cout << '\n'; */ for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { vector<ll> dist(n); vector<int> who(n), allowed(n); for (int k = 0; k <= i; k++) { ckmax(dist[pth[k]], d[0][pth[k]]); who[pth[k]] |= 1; } for (int k = j; k < N; k++) { ckmax(dist[pth[k]], d[1][pth[k]]); who[pth[k]] |= 2; } ll used = 0; for (int v : pth) used += dist[v]; if (used > K) continue; /* cout << "U " << i << " " << j << " " << used << '\n'; for (int x : who) cout << x << " "; cout << '\n'; */ priority_queue<ar<ll, 3>, vector<ar<ll, 3>>, greater<ar<ll, 3>>> q; for (int v : pth) for (int z = 0; z < 2; z++) if (who[v] >> z & 1) { for (auto [u, w] : adj[v]) if (!inpath[u] && !(allowed[u] >> z & 1)) { allowed[u] |= 1 << z; q.push({d[z][u], u, z}); } } while (q.size()) { auto [cost, v, k] = q.top(); q.pop(); if (who[v] >> k & 1) continue; if (used + cost > K) break; used += cost; who[v] |= 1 << k; if (!inpath[v] && allowed[v] == 3 && who[v] < 3) { assert(d[k^1][v] >= d[k][v]); q.push({d[k^1][v] - d[k][v], v, k^1}); } for (auto [u, w] : adj[v]) for (int z = 0; z < 2; z++) if ((who[v] >> z & 1) && !inpath[u] && !(allowed[u] >> z & 1)) { allowed[u] |= 1 << z; q.push({d[z][u], u, z}); } } int cur = 0; for (int x : who) cur += __builtin_popcount(x); /* for (int x : who) cout << x << " "; cout << '\n'; cout << "FInal cost and ans " << used << " " << cur << '\n'; */ ckmax(ans, cur); } } return ans; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...