Submission #1010214

#TimeUsernameProblemLanguageResultExecution timeMemory
1010214thinknoexitClosing Time (IOI23_closing)C++17
8 / 100
74 ms29012 KiB
#include "closing.h" #include <bits/stdc++.h> using namespace std; using ll = long long; int n; priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq; bool vis[200200]; vector<pair<int, int>> adj[200200]; ll dx[200200], dy[200200]; void dfs(int v, int p, ll dis[]) { for (auto& [x, w] : adj[v]) { if (x == p) continue; dis[x] = dis[v] + w; dfs(x, v, dis); } } int max_score(int N, int X, int Y, ll K, vector<int> U, vector<int> V, vector<int> W) { n = N; 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] }); } dx[X] = dy[Y] = 0; dfs(X, -1, dx); dfs(Y, -1, dy); pq.push({ 0, X }), vis[X] = 1; pq.push({ 0, Y }), vis[Y] = 1; int cnt = 0; while (!pq.empty()) { auto x = pq.top(); int v = pq.top().second; ll w = pq.top().first; pq.pop(); if (K - w < 0) break; K -= w; cnt++; for (auto& [x, w] : adj[v]) { if (vis[x]) continue; vis[x] = 1; pq.push({ min(dx[x], dy[x]), x }); } } while (!pq.empty()) pq.pop(); for (int i = 0;i < n;i++) adj[i].clear(), vis[i] = 0; return cnt; }

Compilation message (stderr)

closing.cpp: In function 'int max_score(int, int, int, ll, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:30:14: warning: variable 'x' set but not used [-Wunused-but-set-variable]
   30 |         auto x = pq.top();
      |              ^
#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...