# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28871 | kavun | Race (IOI11_race) | C++14 | 0 ms | 0 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> > adj[300000];
void dfs(int v, int d, int length, int par, int& mn, int K)
{
if(length == K)
{
mn = min(mn,d);
}
else if(length > K)
return;
for(int i = 0; i < adj[v].size(); i++)
{
int u = adj[v][i].first;
if(u != par)
dfs(u,d+1,length + adj[v][i].second,v,mn, K);
}
}
int best_path(int N, int K, int H[][2], int L[])
{
for(int i = 0; i < n-1; i++)
{
int v = H[i][0],u = H[i][1],l = L[i];
adj[v].push_back(make_pair(u,l));
adj[u].push_back(make_pair(v,l));
}
int mn = 1e9;
for(int i = 0; i < N; i++)
{
dfs(i,0,0,i,mn,K);
}
return N;
}