Submission #878195

#TimeUsernameProblemLanguageResultExecution timeMemory
878195SanguineChameleonClosing Time (IOI23_closing)C++17
8 / 100
123 ms38968 KiB
#include "closing.h" #include <bits/stdc++.h> using namespace std; namespace cardboard { int solve(int N, long long K, vector<pair<long long, long long>> boxes) { return 0; } } namespace tree { vector<vector<pair<int, int>>> adj; void init(int N) { adj.resize(N); for (int i = 0; i < N; i++) { adj[i].clear(); } } void add_edge(int u, int v, int w) { adj[u].emplace_back(v, w); adj[v].emplace_back(u, w); } void dfs(int u, int p, vector<long long> &dist) { for (auto [v, w]: adj[u]) { if (v != p) { dist[v] = dist[u] + w; dfs(v, u, dist); } } } } int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W) { tree::init(N); for (int i = 0; i < N - 1; i++) { tree::add_edge(U[i], V[i], W[i]); } vector<long long> distX(N), distY(N); tree::dfs(X, -1, distX); tree::dfs(Y, -1, distY); vector<long long> dists(distX.begin(), distX.end()); dists.insert(dists.end(), distY.begin(), distY.end()); sort(dists.begin(), dists.end()); int res = 0; long long sum = 0; for (auto d: dists) { if (sum + d <= K) { sum += d; res++; } else { break; } } int cnt = 0; vector<pair<long long, long long>> boxes(N); for (int i = 0; i < N; i++) { if (distX[i] + distY[i] == distX[Y]) { cnt++; K -= min(distX[i], distY[i]); boxes[i] = {max(distX[i], distY[i]), K + 1}; } else { boxes[i] = {min(distX[i], distY[i]), max(distX[i], distY[i])}; } } if (K >= 0) { res = max(res, cnt + cardboard::solve(N, K, boxes)); } return res; }
#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...