# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1011628 |
2024-06-30T23:35:11 Z |
LeonidCuk |
Race (IOI11_race) |
C++17 |
|
137 ms |
262144 KB |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>>g[200001];
vector<int>v(200001),sum(200001),sz(200001);
map<long long int,int>*m[200001];
int k,res=10000000;
void dfs(int a,int b,int dep,long long suma)
{
v[a]=dep;
sum[a]=suma;
sz[a]=1;
for(auto p:g[a])
{
if(p.first!=b)
{
dfs(p.second,a,dep+1,suma+p.second);
sz[a]+=sz[p.first];
}
}
}
void findres(int a,int b)
{
int bigc=-1,bigck=-1;
for(auto p:g[a])
{
if(p.first!=b&&sz[p.first]>bigck)
{
bigc=p.first;
bigck=sz[p.first];
}
}
if(bigc==-1)
{
m[a]= new map<long long int,int>();
}
else
{
m[a]=m[bigc];
}
(*m[a])[sum[a]]=v[a];
int t=2*sum[a]+k;
for(auto p:g[a])
{
if(p.first!=bigc&&p.first!=b)
{
for(auto it:*m[p.first])
{
if((*m[a]).find(t-it.first)!=(*m[a]).end())
{
res=min(res,it.second+(*m[a])[t-it.first]-2*v[a]);
}
}
for(auto it:*m[p.first])
{
if((*m[a]).find(it.first)==(*m[a]).end())
{
(*m[a])[it.first]=it.second;
}
else
{
(*m[a])[it.first]=min(it.second,(*m[a])[it.first]);
}
}
}
}
}
int best_path(int N,int K,int H[][2],int L[])
{
k=K;
for(int i=0;i<N-1;i++)
{
int a=H[i][0],b=H[i][1],c=L[i];
g[a].push_back({b,c});
g[b].push_back({a,c});
}
dfs(0,0,0,0);
findres(0,0);
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
137 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
137 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
137 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
137 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |