#include "race.h"
#include <bits/stdc++.h>
using namespace std;
const int maxN=200100;
struct edge{int v,d,nxt;}a[maxN*2];
int k,tmp=0,ans=-1,head[maxN],vis[maxN];
void add(int u,int v,int d){
a[tmp].v=v;a[tmp].d=d;a[tmp].nxt=head[u];head[u]=tmp++;
}
void dfs(int u,int s,int ed){
vis[u]=1;
// printf("to->%d dis:%d vis_edge:%d\n",u,s,ed);
if(s==k){
if(ed<ans||ans==-1)ans=ed;
return;
}
for (int i=head[u];i!=-1;i=a[i].nxt){
int v=a[i].v,d=a[i].d;
if (vis[v])continue;
if(s+d<=k)dfs(v,s+d,ed+1);
}
}
int best_path(int N, int K, int H[][2], int L[]){
k=K;
for (int i=0;i<N;i++)head[i]=-1;
for (int i=0;i<N-1;i++){
add(H[i][0],H[i][1],L[i]);
add(H[i][1],H[i][0],L[i]);
}
for (int i=0;i<N;i++){
memset(vis,0,sizeof(vis));
dfs(i,0,0);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1144 KB |
Output is correct |
2 |
Correct |
7 ms |
1144 KB |
Output is correct |
3 |
Correct |
7 ms |
1144 KB |
Output is correct |
4 |
Correct |
7 ms |
1144 KB |
Output is correct |
5 |
Correct |
7 ms |
1148 KB |
Output is correct |
6 |
Correct |
7 ms |
1144 KB |
Output is correct |
7 |
Correct |
7 ms |
1144 KB |
Output is correct |
8 |
Correct |
8 ms |
1216 KB |
Output is correct |
9 |
Correct |
8 ms |
1144 KB |
Output is correct |
10 |
Correct |
8 ms |
1144 KB |
Output is correct |
11 |
Correct |
7 ms |
1144 KB |
Output is correct |
12 |
Correct |
7 ms |
1272 KB |
Output is correct |
13 |
Correct |
8 ms |
1144 KB |
Output is correct |
14 |
Correct |
7 ms |
1144 KB |
Output is correct |
15 |
Correct |
7 ms |
1144 KB |
Output is correct |
16 |
Correct |
7 ms |
1144 KB |
Output is correct |
17 |
Correct |
7 ms |
1144 KB |
Output is correct |
18 |
Correct |
7 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1144 KB |
Output is correct |
2 |
Correct |
7 ms |
1144 KB |
Output is correct |
3 |
Correct |
7 ms |
1144 KB |
Output is correct |
4 |
Correct |
7 ms |
1144 KB |
Output is correct |
5 |
Correct |
7 ms |
1148 KB |
Output is correct |
6 |
Correct |
7 ms |
1144 KB |
Output is correct |
7 |
Correct |
7 ms |
1144 KB |
Output is correct |
8 |
Correct |
8 ms |
1216 KB |
Output is correct |
9 |
Correct |
8 ms |
1144 KB |
Output is correct |
10 |
Correct |
8 ms |
1144 KB |
Output is correct |
11 |
Correct |
7 ms |
1144 KB |
Output is correct |
12 |
Correct |
7 ms |
1272 KB |
Output is correct |
13 |
Correct |
8 ms |
1144 KB |
Output is correct |
14 |
Correct |
7 ms |
1144 KB |
Output is correct |
15 |
Correct |
7 ms |
1144 KB |
Output is correct |
16 |
Correct |
7 ms |
1144 KB |
Output is correct |
17 |
Correct |
7 ms |
1144 KB |
Output is correct |
18 |
Correct |
7 ms |
1144 KB |
Output is correct |
19 |
Correct |
3 ms |
1144 KB |
Output is correct |
20 |
Correct |
7 ms |
1148 KB |
Output is correct |
21 |
Correct |
55 ms |
1144 KB |
Output is correct |
22 |
Correct |
45 ms |
1144 KB |
Output is correct |
23 |
Correct |
43 ms |
1260 KB |
Output is correct |
24 |
Correct |
43 ms |
1180 KB |
Output is correct |
25 |
Correct |
57 ms |
1272 KB |
Output is correct |
26 |
Correct |
43 ms |
1148 KB |
Output is correct |
27 |
Correct |
42 ms |
1144 KB |
Output is correct |
28 |
Correct |
49 ms |
1244 KB |
Output is correct |
29 |
Correct |
53 ms |
1148 KB |
Output is correct |
30 |
Correct |
52 ms |
1144 KB |
Output is correct |
31 |
Correct |
59 ms |
1148 KB |
Output is correct |
32 |
Correct |
58 ms |
1144 KB |
Output is correct |
33 |
Correct |
53 ms |
1272 KB |
Output is correct |
34 |
Correct |
40 ms |
1144 KB |
Output is correct |
35 |
Correct |
39 ms |
1144 KB |
Output is correct |
36 |
Correct |
39 ms |
1212 KB |
Output is correct |
37 |
Correct |
42 ms |
1144 KB |
Output is correct |
38 |
Correct |
49 ms |
1148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1144 KB |
Output is correct |
2 |
Correct |
7 ms |
1144 KB |
Output is correct |
3 |
Correct |
7 ms |
1144 KB |
Output is correct |
4 |
Correct |
7 ms |
1144 KB |
Output is correct |
5 |
Correct |
7 ms |
1148 KB |
Output is correct |
6 |
Correct |
7 ms |
1144 KB |
Output is correct |
7 |
Correct |
7 ms |
1144 KB |
Output is correct |
8 |
Correct |
8 ms |
1216 KB |
Output is correct |
9 |
Correct |
8 ms |
1144 KB |
Output is correct |
10 |
Correct |
8 ms |
1144 KB |
Output is correct |
11 |
Correct |
7 ms |
1144 KB |
Output is correct |
12 |
Correct |
7 ms |
1272 KB |
Output is correct |
13 |
Correct |
8 ms |
1144 KB |
Output is correct |
14 |
Correct |
7 ms |
1144 KB |
Output is correct |
15 |
Correct |
7 ms |
1144 KB |
Output is correct |
16 |
Correct |
7 ms |
1144 KB |
Output is correct |
17 |
Correct |
7 ms |
1144 KB |
Output is correct |
18 |
Correct |
7 ms |
1144 KB |
Output is correct |
19 |
Execution timed out |
3028 ms |
6392 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1144 KB |
Output is correct |
2 |
Correct |
7 ms |
1144 KB |
Output is correct |
3 |
Correct |
7 ms |
1144 KB |
Output is correct |
4 |
Correct |
7 ms |
1144 KB |
Output is correct |
5 |
Correct |
7 ms |
1148 KB |
Output is correct |
6 |
Correct |
7 ms |
1144 KB |
Output is correct |
7 |
Correct |
7 ms |
1144 KB |
Output is correct |
8 |
Correct |
8 ms |
1216 KB |
Output is correct |
9 |
Correct |
8 ms |
1144 KB |
Output is correct |
10 |
Correct |
8 ms |
1144 KB |
Output is correct |
11 |
Correct |
7 ms |
1144 KB |
Output is correct |
12 |
Correct |
7 ms |
1272 KB |
Output is correct |
13 |
Correct |
8 ms |
1144 KB |
Output is correct |
14 |
Correct |
7 ms |
1144 KB |
Output is correct |
15 |
Correct |
7 ms |
1144 KB |
Output is correct |
16 |
Correct |
7 ms |
1144 KB |
Output is correct |
17 |
Correct |
7 ms |
1144 KB |
Output is correct |
18 |
Correct |
7 ms |
1144 KB |
Output is correct |
19 |
Correct |
3 ms |
1144 KB |
Output is correct |
20 |
Correct |
7 ms |
1148 KB |
Output is correct |
21 |
Correct |
55 ms |
1144 KB |
Output is correct |
22 |
Correct |
45 ms |
1144 KB |
Output is correct |
23 |
Correct |
43 ms |
1260 KB |
Output is correct |
24 |
Correct |
43 ms |
1180 KB |
Output is correct |
25 |
Correct |
57 ms |
1272 KB |
Output is correct |
26 |
Correct |
43 ms |
1148 KB |
Output is correct |
27 |
Correct |
42 ms |
1144 KB |
Output is correct |
28 |
Correct |
49 ms |
1244 KB |
Output is correct |
29 |
Correct |
53 ms |
1148 KB |
Output is correct |
30 |
Correct |
52 ms |
1144 KB |
Output is correct |
31 |
Correct |
59 ms |
1148 KB |
Output is correct |
32 |
Correct |
58 ms |
1144 KB |
Output is correct |
33 |
Correct |
53 ms |
1272 KB |
Output is correct |
34 |
Correct |
40 ms |
1144 KB |
Output is correct |
35 |
Correct |
39 ms |
1144 KB |
Output is correct |
36 |
Correct |
39 ms |
1212 KB |
Output is correct |
37 |
Correct |
42 ms |
1144 KB |
Output is correct |
38 |
Correct |
49 ms |
1148 KB |
Output is correct |
39 |
Execution timed out |
3028 ms |
6392 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |