# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
294756 | Badrangiikh | 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;
int n , x , y , z , *l ;
vector < int > vec [ 1005 ] ;
void go ( int chi , int par , int len , int depth ) {
if ( len == k ) {
ans = min ( ans , depth ) ;
}
for ( int i = 0 ; i < vec [ chi ] . size ( ) ; i ++ ) {
if ( vec [ chi ] [ i ] == par ) continue ;
go ( vec [ chi ] [ i ] , chi , len + l [ vec [ chi ] [ i ] ] , depth + 1 ) ;
}
return ;
}
int best_path(int N, int K, int H[][2], int L[]) {
k = K ;
l = L ;
for ( int i = 0 ; i < N - 1 ; i ++ ) {
vec [ H [ i ] [ 0 ] ] . push_back ( H [ i ] [ 1 ] ) ;
vec [ H [ i ] [ 1 ] ] . push_back ( H [ i ] [ 0 ] ) ;
}
int ans = 1001 ;
for ( int i = 0 ; i < N ; i ++ ) {
go ( i , -1 , 0 , 0 ) ;
}
if ( ans == 1001 ) return -1 ;
else return ans ;
}