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 , k , ans = 10000 ;
vector < int > vec [ 1005 ] ;
map < pair < int , int > , int > mp ;
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 + mp [ { vec [ chi ] [ i ] , chi } ] , depth + 1 ) ;
}
return ;
}
int best_path(int N, int K, int H[][2], int L[])
{
k = K ;
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 ] ) ;
mp [ { H [ i ] [ 0 ] , H [ i ] [ 1 ] } ] = L [ i ] ;
mp [ { H [ i ] [ 1 ] , H [ i ] [ 0 ] } ] = L [ i ] ;
}
for ( int i = 0 ; i < N ; i ++ ) {
go ( i , -1 , 0 , 0 ) ;
}
if ( ans == 10000 ) return -1 ;
else return ans ;
}
Compilation message (stderr)
race.cpp: In function 'void go(int, int, int, int)':
race.cpp:13:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for ( int i = 0 ; i < vec [ chi ] . size ( ) ; i ++ ) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |