Submission #980787

#TimeUsernameProblemLanguageResultExecution timeMemory
980787oleh1421Closing Time (IOI23_closing)C++17
0 / 100
231 ms48436 KiB
#include "closing.h" #include <bits/stdc++.h> typedef long long ll; using namespace std; vector<vector<pair<int,ll> > >g; vector<vector<ll> >d; vector<int>p; void dfs(int v,int pr,int j){ p[v]=pr; for (auto [to,w]:g[v]){ if (to==pr) continue; d[j][to]=d[j][v]+w; dfs(to,v,j); } } int max_score(int N, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W) { g.clear(); d.clear(); p.clear(); g.resize(N+1); d.resize(2,vector<ll>(N+1,0)); p.resize(N+1,-1); for (int i=0;i<N-1;i++){ g[U[i]].push_back({V[i],W[i]}); g[V[i]].push_back({U[i],W[i]}); } { d[0][X]=0; dfs(X,-1,0); } { d[1][Y]=0; dfs(Y,-1,1); } set<pair<ll,int> >st; vector<pair<ll,int> >v; for (int i=0;i<N;i++){ st.insert({min(d[0][i],d[1][i]),i}); v.push_back({max(d[0][i],d[1][i]),i}); } sort(v.begin(),v.end()); ll sum=0ll; int ans=2; int cnt1=0; for (auto [dist,i]:v){ int cnt2=0; ll sum2=sum; for (auto cur:st){ sum2+=cur.first; if (sum2>K) break; cnt2++; } ans=max(ans,cnt1+cnt2); sum+=dist; st.erase({min(d[0][i],d[1][i]),i}); cnt1++; } if (sum<=K){ ans=2*N; } 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...