# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
345065 | daniel920712 | 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 <vector>
#include <utility>
using namespace std;
long long ans=1000000000;
vector < pair < long long , long long > > Next[200005];
void F(long long fa,long long here,long long dis,long long deg,long long K)
{
if(dis==K) ans=min(ans,deg);
if(dis>=K) return ;
for(auto i:Next[here]) if(i.first!=fa) F(here,i.first,dis+i.second,deg+1,K);
}
int best_path(long long N, long long K, long long H[][2], long long L[])
{
long long i;
for(i=1;i<N;i++)
{
Next[H[i][0]].push_back(make_pair(H[i][1],L[i]));
Next[H[i][1]].push_back(make_pair(H[i][0],L[i]));
}
for(i=0;i<N;i++) F(-1,i,0,0,K);
if(ans==1000000000) ans=-1;
return (int) ans;
}