//#include "race.h"
#include<bits/stdc++.h>
using namespace std;
struct point{
int u,x,y,par;
};
int ans=INT_MAX;
vector<vector<pair<int,int>>>adj(2e5);
void dfs(int j,int score,int level,int par,int K){
if (score>K)return ;
if (score==K){
ans=min(ans,level);
return ;
}
for (auto x:adj[j]){
if (x.first!=par){
dfs(x.first,score+x.second,level+1,j,K);
}
}
}
int best_path(int N, int K, int H[][2], int L[])
{
for (int i =0;i<N-1;++i){
adj[H[i][0]].push_back({H[i][1],L[i]});
adj[H[i][1]].push_back({H[i][0],L[i]});
}
for (int i =0;i<N;++i)
dfs(i,0,0,-1,K);
if (ans==INT_MAX)return -1;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
5016 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
5068 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
4 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
4 ms |
4940 KB |
Output is correct |
15 |
Correct |
4 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
5004 KB |
Output is correct |
17 |
Correct |
4 ms |
5008 KB |
Output is correct |
18 |
Correct |
4 ms |
5004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
5016 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
5068 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
4 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
4 ms |
4940 KB |
Output is correct |
15 |
Correct |
4 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
5004 KB |
Output is correct |
17 |
Correct |
4 ms |
5008 KB |
Output is correct |
18 |
Correct |
4 ms |
5004 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
19 ms |
5072 KB |
Output is correct |
22 |
Correct |
5 ms |
5068 KB |
Output is correct |
23 |
Correct |
4 ms |
5068 KB |
Output is correct |
24 |
Correct |
4 ms |
5024 KB |
Output is correct |
25 |
Correct |
17 ms |
5072 KB |
Output is correct |
26 |
Correct |
4 ms |
5068 KB |
Output is correct |
27 |
Correct |
4 ms |
5068 KB |
Output is correct |
28 |
Correct |
7 ms |
5068 KB |
Output is correct |
29 |
Correct |
11 ms |
5020 KB |
Output is correct |
30 |
Correct |
12 ms |
5076 KB |
Output is correct |
31 |
Correct |
16 ms |
5076 KB |
Output is correct |
32 |
Correct |
16 ms |
5080 KB |
Output is correct |
33 |
Correct |
16 ms |
5020 KB |
Output is correct |
34 |
Correct |
4 ms |
5020 KB |
Output is correct |
35 |
Correct |
5 ms |
5068 KB |
Output is correct |
36 |
Correct |
5 ms |
4940 KB |
Output is correct |
37 |
Correct |
11 ms |
5080 KB |
Output is correct |
38 |
Correct |
13 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
5016 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
5068 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
4 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
4 ms |
4940 KB |
Output is correct |
15 |
Correct |
4 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
5004 KB |
Output is correct |
17 |
Correct |
4 ms |
5008 KB |
Output is correct |
18 |
Correct |
4 ms |
5004 KB |
Output is correct |
19 |
Execution timed out |
3056 ms |
11076 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
5016 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
5068 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
4 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
4 ms |
4940 KB |
Output is correct |
15 |
Correct |
4 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
5004 KB |
Output is correct |
17 |
Correct |
4 ms |
5008 KB |
Output is correct |
18 |
Correct |
4 ms |
5004 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
19 ms |
5072 KB |
Output is correct |
22 |
Correct |
5 ms |
5068 KB |
Output is correct |
23 |
Correct |
4 ms |
5068 KB |
Output is correct |
24 |
Correct |
4 ms |
5024 KB |
Output is correct |
25 |
Correct |
17 ms |
5072 KB |
Output is correct |
26 |
Correct |
4 ms |
5068 KB |
Output is correct |
27 |
Correct |
4 ms |
5068 KB |
Output is correct |
28 |
Correct |
7 ms |
5068 KB |
Output is correct |
29 |
Correct |
11 ms |
5020 KB |
Output is correct |
30 |
Correct |
12 ms |
5076 KB |
Output is correct |
31 |
Correct |
16 ms |
5076 KB |
Output is correct |
32 |
Correct |
16 ms |
5080 KB |
Output is correct |
33 |
Correct |
16 ms |
5020 KB |
Output is correct |
34 |
Correct |
4 ms |
5020 KB |
Output is correct |
35 |
Correct |
5 ms |
5068 KB |
Output is correct |
36 |
Correct |
5 ms |
4940 KB |
Output is correct |
37 |
Correct |
11 ms |
5080 KB |
Output is correct |
38 |
Correct |
13 ms |
5072 KB |
Output is correct |
39 |
Execution timed out |
3056 ms |
11076 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |