Submission #1007068

#TimeUsernameProblemLanguageResultExecution timeMemory
1007068Haidara314Closing Time (IOI23_closing)C++17
0 / 100
1008 ms27580 KiB
#include "closing.h" #include <bits/stdc++.h> #define S second #define F first #define ll long long using namespace std; vector<pair<int,ll>>adj[200005]; vector<int>v; vector<ll>p; void dfs(int u,int v1) { v.push_back(u); for(auto x:adj[u]) { if(x.F!=v1) { p.push_back(x.S); dfs(x.F,u); } } } int max_score(int N, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W) { p.clear(); v.clear(); for(int i=0;i<N;i++) { adj[i].clear(); } 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]}); //cout<<U[i]<<" "<<V[i]<<endl; } ll ans=0; int x; for(int i=0;i<N;i++) { if(adj[i].size()==1){x=i;} } dfs(x,x); int s1; int s2; for(int i=0;i<N;i++) { if(v[i]==X)s1=i; if(v[i]==Y)s2=i; } ll o=0; for(int i=s1;i>=0;i--) { ll h=0; for(int j=s2;j>=0;j--) { ll g=0; for(int k=s1;k<N;k++) { ll f=0; for(int z=s2;z<N;z++) { if(K>=o+g+h+f){//cout<<i<<" "<<j<<" "<<k<<" "<<z<<" "<<s1-i+1+s2-j+1+k-s1+z-s2<<endl; //cout<<o<<" "<<h<<" "<<g<<" "<<f<<endl; ans=max(ans,(ll)(s1-i+1+s2-j+1+k-s1+z-s2));} f+=f+p[z]; } g+=g+p[k]; } h+=h+p[j-1]; } o+=o+p[i-1]; } return ans; } /* 1 7 0 2 10 0 0 1 2 2 5 1 3 2 4 5 6 2 3 4 2 5 3 */ /* 1 4 0 3 20 0 1 18 1 2 1 2 3 19 */

Compilation message (stderr)

closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:44:8: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |     dfs(x,x);
      |     ~~~^~~~~
closing.cpp:45:9: warning: 's1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |     int s1;
      |         ^~
#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...