| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 849175 | abcvuitunggio | Race (IOI11_race) | C++17 | 315 ms | 80208 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 "race.h"
#include <bits/stdc++.h>
using namespace std;
vector <pair <int, int>> ke[200001];
map <long long, long long> mp[200001];
long long k,len[200001],res=1e9,d[200001];
void dfs(int u, int p){
int bigchild=-1,sz=0;
for (auto [v,w]:ke[u])
if (v!=p){
d[v]=d[u]+1;
len[v]=len[u]+w;
dfs(v,u);
if (mp[v].size()>sz){
sz=mp[v].size();
bigchild=v;
}
}
if (bigchild!=-1)
swap(mp[u],mp[bigchild]);
for (auto [v,w]:ke[u]){
if (v!=bigchild){
for (auto [l,h]:mp[v])
if (mp[u].count(k+len[u]*2-l))
res=min(res,mp[u][k+len[u]*2-l]+h-d[u]*2);
for (auto [l,h]:mp[v])
if (!mp[u].count(l))
mp[u][l]=h;
else
mp[u][l]=min(mp[u][l],h);
mp[v].clear();
}
}
if (mp[u].count(k+len[u]))
res=min(res,mp[u][k+len[u]]-d[u]);
if (!mp[u].count(len[u]))
mp[u][len[u]]=d[u];
else
mp[u][len[u]]=min(mp[u][len[u]],d[u]);
}
int best_path(int N, int K, int H[][2], int L[]){
k=K;
for (int i=0;i<N-1;i++){
ke[H[i][0]].push_back({H[i][1],L[i]});
ke[H[i][1]].push_back({H[i][0],L[i]});
}
dfs(0,0);
return (res>N?-1:res);
}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... | ||||
