| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1304552 | h1drogen | Race (IOI11_race) | C++20 | 0 ms | 0 KiB |
int best_path(int N, int K, int H[][2], int L[]) {
vector<vector<pair<int,int>>> g(N);
for(int i=0;i<N-1;i++){
g[H[i][0]].push_back({H[i][1], L[i]});
g[H[i][1]].push_back({H[i][0], L[i]});
}
int answer = INT_MAX;
function<void(int,int,int,int)> dfs = [&](int v,int p,int length,int edges){
if(length == K){
answer = min(answer, edges);
return;
}
if(length > K) return;
for(auto [u,w]: g[v]){
if(u != p){
dfs(u, v, length+w, edges+1);
}
}
};
for(int i=0;i<N;i++){
dfs(i,-1,0,0);
}
return answer == INT_MAX ? -1 : answer;
}
