Submission #900073

#TimeUsernameProblemLanguageResultExecution timeMemory
900073bleahbleahClosing Time (IOI23_closing)C++17
0 / 100
48 ms13576 KiB
#include <bits/stdc++.h> #include "closing.h" #define all(x) (x).begin(),(x).end() using namespace std; using ll = long long; using ld = long double; //#define int ll #define sz(x) ((int)(x).size()) using pii = pair<ll,ll>; using tii = tuple<int,int,int>; const int nmax = 2e3 + 5; vector<pii> g[nmax]; vector<ll> dX, dY; vector<int> occX; vector<int> chain; void dfs(int node, int f, vector<ll>& d, ll accum) { d[node] = accum; for(auto [x, c] : g[node]) if(x != f) dfs(x, node, d, accum + c); return; } void findchain(int node, int f, int Y) { if(sz(chain) && chain.back() == Y) return; chain.emplace_back(node); for(auto [x, e] : g[node]) { if(x == f) continue; findchain(x, node, Y); } if(chain.back() == Y) return; chain.pop_back(); } int disjointed(int n, ll K, int X, int Y) { priority_queue<pii, vector<pii>, greater<pii>> heap; vector<int> occY(n, 0); heap.emplace(0, Y); int scorefromY = 0; while(!heap.empty()) { auto [C, node] = heap.top(); K -= C; if(K < 0) break; heap.pop(); occY[node] = 1; scorefromY++; for(auto [x, e] : g[node]) { if(occX[x] || occY[x]) continue; heap.emplace(C + e, x); } } return scorefromY; } int tied(int n, ll K, int X, int Y) { int scorefromY = 0; priority_queue<pii, vector<pii>, greater<pii>> heap; vector<ll> costs(n); vector<int> occY(n, 0); for(int i = 0; i < n; i++) costs[i] = occX[i]? max(0LL, dY[i] - dX[i]) : dY[i]; for(auto x : chain) { occY[x] = 1; if(occX[x] == 1) break; } for(auto x : chain) { if(!occY[x]) continue; scorefromY++; K -= costs[x]; for(auto [nv, e] : g[x]) { if(occY[nv]) continue; heap.emplace(costs[nv], nv); } } if(K < 0) return 1; while(!heap.empty()) { auto [C, node] = heap.top(); K -= C; if(K < 0) break; heap.pop(); occY[node] = 1; scorefromY++; for(auto [x, e] : g[node]) { if(occX[x] || occY[x]) continue; heap.emplace(costs[x], x); } } return scorefromY; } int max_score(int n, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W) { for(int i = 0; i < n; i++) g[i].clear(); chain.clear(); dX.clear(); dY.clear(); occX.clear(); for(int i = 0; i < n - 1; i++) g[U[i]].emplace_back(V[i], W[i]), g[V[i]].emplace_back(U[i], W[i]); dX.resize(n); dY.resize(n); dfs(X, X, dX, 0); dfs(Y, Y, dY, 0); findchain(X, X, Y); reverse(all(chain)); priority_queue<pii, vector<pii>, greater<pii>> heap; heap.emplace(0, X); occX.resize(n); int scorefromX = 0; int maxscore = 2; while(!heap.empty()) { auto [C, node] = heap.top(); K -= C; //cerr << node << '\n'; if(K < 0) break; heap.pop(); scorefromX++; occX[node] = 1; for(auto [x, e] : g[node]) { if(!occX[x]) heap.emplace(C + e, x); } maxscore = max(maxscore, scorefromX + max(disjointed(n, K, X, Y), tied(n, K, X, Y))); } return maxscore; }
#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...