#include "race.h"
#include <vector>
using namespace std;
int best;
void dfs(int a,int par,vector<vector<pair<int,int>>>& g,int cnt,int dist,int k){
if(cnt==k)best=min(best,dist);
for(auto x:g[a]){
if(x.first==par)continue;
dfs(x.first,a,g,cnt+x.second,dist+1,k);
}
}
int best_path(int N, int K, int H[][2], int L[]){
vector<vector<pair<int,int>>> g(N,vector<pair<int,int>>());
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]});
}
best=1e9;
for(int i=0;i<N;i++)dfs(i,i,g,0,0,K);
if(best==1e9)best=-1;
return best;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
292 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
224 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
296 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
292 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
224 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
296 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
12 ms |
384 KB |
Output is correct |
22 |
Correct |
13 ms |
340 KB |
Output is correct |
23 |
Correct |
13 ms |
340 KB |
Output is correct |
24 |
Correct |
13 ms |
384 KB |
Output is correct |
25 |
Correct |
12 ms |
340 KB |
Output is correct |
26 |
Correct |
13 ms |
388 KB |
Output is correct |
27 |
Correct |
14 ms |
340 KB |
Output is correct |
28 |
Correct |
13 ms |
392 KB |
Output is correct |
29 |
Correct |
11 ms |
388 KB |
Output is correct |
30 |
Correct |
13 ms |
384 KB |
Output is correct |
31 |
Correct |
11 ms |
340 KB |
Output is correct |
32 |
Correct |
12 ms |
340 KB |
Output is correct |
33 |
Correct |
15 ms |
368 KB |
Output is correct |
34 |
Correct |
9 ms |
340 KB |
Output is correct |
35 |
Correct |
9 ms |
340 KB |
Output is correct |
36 |
Correct |
9 ms |
340 KB |
Output is correct |
37 |
Correct |
8 ms |
340 KB |
Output is correct |
38 |
Correct |
12 ms |
388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
292 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
224 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
296 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Execution timed out |
3040 ms |
8736 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
292 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
224 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
296 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
12 ms |
384 KB |
Output is correct |
22 |
Correct |
13 ms |
340 KB |
Output is correct |
23 |
Correct |
13 ms |
340 KB |
Output is correct |
24 |
Correct |
13 ms |
384 KB |
Output is correct |
25 |
Correct |
12 ms |
340 KB |
Output is correct |
26 |
Correct |
13 ms |
388 KB |
Output is correct |
27 |
Correct |
14 ms |
340 KB |
Output is correct |
28 |
Correct |
13 ms |
392 KB |
Output is correct |
29 |
Correct |
11 ms |
388 KB |
Output is correct |
30 |
Correct |
13 ms |
384 KB |
Output is correct |
31 |
Correct |
11 ms |
340 KB |
Output is correct |
32 |
Correct |
12 ms |
340 KB |
Output is correct |
33 |
Correct |
15 ms |
368 KB |
Output is correct |
34 |
Correct |
9 ms |
340 KB |
Output is correct |
35 |
Correct |
9 ms |
340 KB |
Output is correct |
36 |
Correct |
9 ms |
340 KB |
Output is correct |
37 |
Correct |
8 ms |
340 KB |
Output is correct |
38 |
Correct |
12 ms |
388 KB |
Output is correct |
39 |
Execution timed out |
3040 ms |
8736 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |