#include <bits/stdc++.h>
#include "race.h"
using namespace std;
const int mx = 2e5+1;
#define F first
#define S second
vector<vector<pair<int,int>>> adj(mx);
map<int,int> arr[mx];
int ans=1e9;
void dfs(int node, int par, int dep, int depth, int k){
for(auto x: adj[node])if(x.F != par){
dfs(x.F, node, dep+1, depth + x.S, k);
if(arr[x.F].size() > arr[node].size()) swap(arr[node], arr[x.F]);
for(auto thing: arr[x.F])if(arr[node].count(k + 2 * depth - thing.F)) ans = min(ans, arr[node][k+2*depth-thing.F]+thing.S - 2*dep);
for(auto thing: arr[x.F]){
if(arr[node].count(thing.F)) arr[node][thing.F] = min(arr[node][thing.F], thing.S);
else arr[node][thing.F] = thing.S;
}
}
if(arr[node].count(k + depth)) ans = min(ans, arr[node][k+depth] - dep);
arr[node][depth] = dep;
}
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]});
}
dfs(0,0,0,0,k);
return (ans == 1e9 ? -1 : ans);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
18012 KB |
Output is correct |
2 |
Correct |
4 ms |
18012 KB |
Output is correct |
3 |
Correct |
5 ms |
18012 KB |
Output is correct |
4 |
Correct |
4 ms |
18012 KB |
Output is correct |
5 |
Correct |
6 ms |
18012 KB |
Output is correct |
6 |
Correct |
5 ms |
18012 KB |
Output is correct |
7 |
Correct |
5 ms |
18012 KB |
Output is correct |
8 |
Correct |
4 ms |
18012 KB |
Output is correct |
9 |
Correct |
4 ms |
18012 KB |
Output is correct |
10 |
Correct |
5 ms |
18144 KB |
Output is correct |
11 |
Correct |
4 ms |
18012 KB |
Output is correct |
12 |
Correct |
5 ms |
18012 KB |
Output is correct |
13 |
Correct |
4 ms |
18012 KB |
Output is correct |
14 |
Correct |
5 ms |
18008 KB |
Output is correct |
15 |
Correct |
4 ms |
18012 KB |
Output is correct |
16 |
Correct |
5 ms |
18012 KB |
Output is correct |
17 |
Correct |
6 ms |
18012 KB |
Output is correct |
18 |
Correct |
4 ms |
18012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
18012 KB |
Output is correct |
2 |
Correct |
4 ms |
18012 KB |
Output is correct |
3 |
Correct |
5 ms |
18012 KB |
Output is correct |
4 |
Correct |
4 ms |
18012 KB |
Output is correct |
5 |
Correct |
6 ms |
18012 KB |
Output is correct |
6 |
Correct |
5 ms |
18012 KB |
Output is correct |
7 |
Correct |
5 ms |
18012 KB |
Output is correct |
8 |
Correct |
4 ms |
18012 KB |
Output is correct |
9 |
Correct |
4 ms |
18012 KB |
Output is correct |
10 |
Correct |
5 ms |
18144 KB |
Output is correct |
11 |
Correct |
4 ms |
18012 KB |
Output is correct |
12 |
Correct |
5 ms |
18012 KB |
Output is correct |
13 |
Correct |
4 ms |
18012 KB |
Output is correct |
14 |
Correct |
5 ms |
18008 KB |
Output is correct |
15 |
Correct |
4 ms |
18012 KB |
Output is correct |
16 |
Correct |
5 ms |
18012 KB |
Output is correct |
17 |
Correct |
6 ms |
18012 KB |
Output is correct |
18 |
Correct |
4 ms |
18012 KB |
Output is correct |
19 |
Correct |
5 ms |
18012 KB |
Output is correct |
20 |
Correct |
4 ms |
17972 KB |
Output is correct |
21 |
Correct |
7 ms |
18264 KB |
Output is correct |
22 |
Correct |
6 ms |
18268 KB |
Output is correct |
23 |
Correct |
5 ms |
18264 KB |
Output is correct |
24 |
Correct |
6 ms |
18212 KB |
Output is correct |
25 |
Correct |
6 ms |
18268 KB |
Output is correct |
26 |
Correct |
5 ms |
18204 KB |
Output is correct |
27 |
Correct |
6 ms |
18264 KB |
Output is correct |
28 |
Correct |
6 ms |
18192 KB |
Output is correct |
29 |
Correct |
5 ms |
18268 KB |
Output is correct |
30 |
Correct |
5 ms |
18268 KB |
Output is correct |
31 |
Correct |
5 ms |
18188 KB |
Output is correct |
32 |
Correct |
5 ms |
18268 KB |
Output is correct |
33 |
Correct |
6 ms |
18268 KB |
Output is correct |
34 |
Correct |
4 ms |
18268 KB |
Output is correct |
35 |
Correct |
5 ms |
18268 KB |
Output is correct |
36 |
Correct |
5 ms |
18268 KB |
Output is correct |
37 |
Correct |
6 ms |
18268 KB |
Output is correct |
38 |
Correct |
5 ms |
18268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
18012 KB |
Output is correct |
2 |
Correct |
4 ms |
18012 KB |
Output is correct |
3 |
Correct |
5 ms |
18012 KB |
Output is correct |
4 |
Correct |
4 ms |
18012 KB |
Output is correct |
5 |
Correct |
6 ms |
18012 KB |
Output is correct |
6 |
Correct |
5 ms |
18012 KB |
Output is correct |
7 |
Correct |
5 ms |
18012 KB |
Output is correct |
8 |
Correct |
4 ms |
18012 KB |
Output is correct |
9 |
Correct |
4 ms |
18012 KB |
Output is correct |
10 |
Correct |
5 ms |
18144 KB |
Output is correct |
11 |
Correct |
4 ms |
18012 KB |
Output is correct |
12 |
Correct |
5 ms |
18012 KB |
Output is correct |
13 |
Correct |
4 ms |
18012 KB |
Output is correct |
14 |
Correct |
5 ms |
18008 KB |
Output is correct |
15 |
Correct |
4 ms |
18012 KB |
Output is correct |
16 |
Correct |
5 ms |
18012 KB |
Output is correct |
17 |
Correct |
6 ms |
18012 KB |
Output is correct |
18 |
Correct |
4 ms |
18012 KB |
Output is correct |
19 |
Correct |
81 ms |
32336 KB |
Output is correct |
20 |
Correct |
88 ms |
33672 KB |
Output is correct |
21 |
Correct |
94 ms |
33104 KB |
Output is correct |
22 |
Correct |
94 ms |
33872 KB |
Output is correct |
23 |
Correct |
116 ms |
43600 KB |
Output is correct |
24 |
Correct |
94 ms |
38336 KB |
Output is correct |
25 |
Correct |
55 ms |
33360 KB |
Output is correct |
26 |
Correct |
43 ms |
39764 KB |
Output is correct |
27 |
Correct |
135 ms |
39144 KB |
Output is correct |
28 |
Correct |
159 ms |
68832 KB |
Output is correct |
29 |
Correct |
181 ms |
67652 KB |
Output is correct |
30 |
Correct |
136 ms |
39708 KB |
Output is correct |
31 |
Correct |
135 ms |
39696 KB |
Output is correct |
32 |
Correct |
174 ms |
39728 KB |
Output is correct |
33 |
Correct |
156 ms |
38480 KB |
Output is correct |
34 |
Correct |
259 ms |
62800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
18012 KB |
Output is correct |
2 |
Correct |
4 ms |
18012 KB |
Output is correct |
3 |
Correct |
5 ms |
18012 KB |
Output is correct |
4 |
Correct |
4 ms |
18012 KB |
Output is correct |
5 |
Correct |
6 ms |
18012 KB |
Output is correct |
6 |
Correct |
5 ms |
18012 KB |
Output is correct |
7 |
Correct |
5 ms |
18012 KB |
Output is correct |
8 |
Correct |
4 ms |
18012 KB |
Output is correct |
9 |
Correct |
4 ms |
18012 KB |
Output is correct |
10 |
Correct |
5 ms |
18144 KB |
Output is correct |
11 |
Correct |
4 ms |
18012 KB |
Output is correct |
12 |
Correct |
5 ms |
18012 KB |
Output is correct |
13 |
Correct |
4 ms |
18012 KB |
Output is correct |
14 |
Correct |
5 ms |
18008 KB |
Output is correct |
15 |
Correct |
4 ms |
18012 KB |
Output is correct |
16 |
Correct |
5 ms |
18012 KB |
Output is correct |
17 |
Correct |
6 ms |
18012 KB |
Output is correct |
18 |
Correct |
4 ms |
18012 KB |
Output is correct |
19 |
Correct |
5 ms |
18012 KB |
Output is correct |
20 |
Correct |
4 ms |
17972 KB |
Output is correct |
21 |
Correct |
7 ms |
18264 KB |
Output is correct |
22 |
Correct |
6 ms |
18268 KB |
Output is correct |
23 |
Correct |
5 ms |
18264 KB |
Output is correct |
24 |
Correct |
6 ms |
18212 KB |
Output is correct |
25 |
Correct |
6 ms |
18268 KB |
Output is correct |
26 |
Correct |
5 ms |
18204 KB |
Output is correct |
27 |
Correct |
6 ms |
18264 KB |
Output is correct |
28 |
Correct |
6 ms |
18192 KB |
Output is correct |
29 |
Correct |
5 ms |
18268 KB |
Output is correct |
30 |
Correct |
5 ms |
18268 KB |
Output is correct |
31 |
Correct |
5 ms |
18188 KB |
Output is correct |
32 |
Correct |
5 ms |
18268 KB |
Output is correct |
33 |
Correct |
6 ms |
18268 KB |
Output is correct |
34 |
Correct |
4 ms |
18268 KB |
Output is correct |
35 |
Correct |
5 ms |
18268 KB |
Output is correct |
36 |
Correct |
5 ms |
18268 KB |
Output is correct |
37 |
Correct |
6 ms |
18268 KB |
Output is correct |
38 |
Correct |
5 ms |
18268 KB |
Output is correct |
39 |
Correct |
81 ms |
32336 KB |
Output is correct |
40 |
Correct |
88 ms |
33672 KB |
Output is correct |
41 |
Correct |
94 ms |
33104 KB |
Output is correct |
42 |
Correct |
94 ms |
33872 KB |
Output is correct |
43 |
Correct |
116 ms |
43600 KB |
Output is correct |
44 |
Correct |
94 ms |
38336 KB |
Output is correct |
45 |
Correct |
55 ms |
33360 KB |
Output is correct |
46 |
Correct |
43 ms |
39764 KB |
Output is correct |
47 |
Correct |
135 ms |
39144 KB |
Output is correct |
48 |
Correct |
159 ms |
68832 KB |
Output is correct |
49 |
Correct |
181 ms |
67652 KB |
Output is correct |
50 |
Correct |
136 ms |
39708 KB |
Output is correct |
51 |
Correct |
135 ms |
39696 KB |
Output is correct |
52 |
Correct |
174 ms |
39728 KB |
Output is correct |
53 |
Correct |
156 ms |
38480 KB |
Output is correct |
54 |
Correct |
259 ms |
62800 KB |
Output is correct |
55 |
Correct |
15 ms |
20316 KB |
Output is correct |
56 |
Correct |
11 ms |
19036 KB |
Output is correct |
57 |
Correct |
51 ms |
31524 KB |
Output is correct |
58 |
Correct |
44 ms |
29844 KB |
Output is correct |
59 |
Correct |
64 ms |
44696 KB |
Output is correct |
60 |
Correct |
160 ms |
67920 KB |
Output is correct |
61 |
Correct |
176 ms |
41456 KB |
Output is correct |
62 |
Correct |
149 ms |
39528 KB |
Output is correct |
63 |
Correct |
166 ms |
39504 KB |
Output is correct |
64 |
Correct |
351 ms |
77620 KB |
Output is correct |
65 |
Correct |
328 ms |
79348 KB |
Output is correct |
66 |
Correct |
178 ms |
62012 KB |
Output is correct |
67 |
Correct |
125 ms |
40816 KB |
Output is correct |
68 |
Correct |
279 ms |
53796 KB |
Output is correct |
69 |
Correct |
294 ms |
55572 KB |
Output is correct |
70 |
Correct |
242 ms |
52996 KB |
Output is correct |