# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1007020 | Haidara314 | Closing Time (IOI23_closing) | C++17 | 1014 ms | 32012 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
{
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;
vector<ll>ox;
ox.push_back(0);
for(int i=s1;i>0;i--)
{
o+=o+p[i-1];
ox.push_back(o);
}
ox.pop_back();
for(int i=0;i<=s1;i++)
{
//cout<<o<<endl;
ll h=0;
vector<ll>hx;
hx.push_back(h);
for(int i1=s2;i1>0;i1--)
{
h+=h+p[i1];
hx.push_back(h);
}
hx.pop_back();
for(int j=0;j<=s2;j++)
{
ll g=0;
vector<ll>gx;
gx.push_back(0);
for(int i1=s1;i1<N-1;i1++){
g+=g+p[i1];
gx.push_back(g);
}
gx.pop_back();
for(int k=N-1;k>=s1;k--)
{
ll ans1=0;
if(K>=g+h+o)
{
ll k1=K-g-o-h;
ans1+=s1-i+1;
ans1+=s2-j+1;
ans1+=k-s1;
ll kk=0;
ans=max(ans,ans1);
for(int z=s2;z<N-1;z++)
{
if(kk<=k1)
{
ans=max(ans,ans1+z-s2);
}
kk+=kk+p[z];
}
}
g=gx[gx.size()-1];
gx.pop_back();
}
h=hx[hx.size()-1];
hx.pop_back();
}
o=ox[ox.size()-1];
ox.pop_back();
}
return N;
}
/*
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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |