#include "race.h"
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
int n, k, mn;
vector< pair<int, int> > g[200005];
void dfs(int v, int par, map<int, int> &mp, int depth, long long distance){
mp[distance] = depth;
for(auto [to, w] : g[v]){
if(to == par) continue;
map<int, int> sub;
dfs(to, v, sub, depth + 1, distance + w);
if(mp.size() < sub.size()) swap(mp, sub);
for(auto &u : sub){
int d = 2*distance - u.ff + k;
if(mp.count(d)){
mn = min(mn, mp[d] + u.ss - 2*depth);
}
}
for(auto &u : sub){
if(mp.count(u.ff)) mp[u.ff] = min(mp[u.ff], u.ss);
else{
mp[u.ff] = u.ss;
}
}
}
}
int best_path(int N, int K, int H[][2], int L[]){
n = N, k = K, mn = N+1;
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]});
}
map<int, int> mp;
dfs(0, 0, mp, 0, 0);
if(mn == n+1) mn = -1;
return mn;
}
//main(){
// int N, K; cin >> N >> K;
// int H[N-1][2], L[N-1];
// for(int i = 0; i < N-1; i++){
// cin >> H[i][0] >> H[i][1];
// }
// for(int i = 0;i < N-1; i++) cin >> L[i];
// cout << best_path(N, K, H, L);
//}
Compilation message
race.cpp: In function 'void dfs(int, int, std::map<int, int>&, int, long long int)':
race.cpp:14:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
14 | for(auto [to, w] : g[v]){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5012 KB |
Output is correct |
2 |
Correct |
3 ms |
4980 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
5008 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
5008 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5004 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
5012 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5012 KB |
Output is correct |
2 |
Correct |
3 ms |
4980 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
5008 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
5008 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5004 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
5012 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
5072 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
5076 KB |
Output is correct |
25 |
Correct |
3 ms |
5076 KB |
Output is correct |
26 |
Correct |
3 ms |
5016 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
3 ms |
5076 KB |
Output is correct |
29 |
Correct |
3 ms |
5076 KB |
Output is correct |
30 |
Correct |
3 ms |
5076 KB |
Output is correct |
31 |
Correct |
3 ms |
5016 KB |
Output is correct |
32 |
Correct |
3 ms |
5016 KB |
Output is correct |
33 |
Correct |
3 ms |
5024 KB |
Output is correct |
34 |
Correct |
3 ms |
5148 KB |
Output is correct |
35 |
Correct |
3 ms |
5076 KB |
Output is correct |
36 |
Correct |
3 ms |
5076 KB |
Output is correct |
37 |
Correct |
3 ms |
5076 KB |
Output is correct |
38 |
Correct |
3 ms |
5148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5012 KB |
Output is correct |
2 |
Correct |
3 ms |
4980 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
5008 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
5008 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5004 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
5012 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
62 ms |
11152 KB |
Output is correct |
20 |
Correct |
64 ms |
11224 KB |
Output is correct |
21 |
Correct |
59 ms |
11244 KB |
Output is correct |
22 |
Correct |
62 ms |
11348 KB |
Output is correct |
23 |
Correct |
88 ms |
11628 KB |
Output is correct |
24 |
Correct |
68 ms |
11464 KB |
Output is correct |
25 |
Correct |
63 ms |
24844 KB |
Output is correct |
26 |
Correct |
49 ms |
37140 KB |
Output is correct |
27 |
Correct |
110 ms |
18064 KB |
Output is correct |
28 |
Correct |
167 ms |
69748 KB |
Output is correct |
29 |
Correct |
176 ms |
67188 KB |
Output is correct |
30 |
Correct |
114 ms |
17996 KB |
Output is correct |
31 |
Correct |
111 ms |
18036 KB |
Output is correct |
32 |
Correct |
114 ms |
18232 KB |
Output is correct |
33 |
Correct |
122 ms |
17480 KB |
Output is correct |
34 |
Correct |
212 ms |
27952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5012 KB |
Output is correct |
2 |
Correct |
3 ms |
4980 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
5008 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
5008 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5004 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
5012 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
5072 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
5076 KB |
Output is correct |
25 |
Correct |
3 ms |
5076 KB |
Output is correct |
26 |
Correct |
3 ms |
5016 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
3 ms |
5076 KB |
Output is correct |
29 |
Correct |
3 ms |
5076 KB |
Output is correct |
30 |
Correct |
3 ms |
5076 KB |
Output is correct |
31 |
Correct |
3 ms |
5016 KB |
Output is correct |
32 |
Correct |
3 ms |
5016 KB |
Output is correct |
33 |
Correct |
3 ms |
5024 KB |
Output is correct |
34 |
Correct |
3 ms |
5148 KB |
Output is correct |
35 |
Correct |
3 ms |
5076 KB |
Output is correct |
36 |
Correct |
3 ms |
5076 KB |
Output is correct |
37 |
Correct |
3 ms |
5076 KB |
Output is correct |
38 |
Correct |
3 ms |
5148 KB |
Output is correct |
39 |
Correct |
62 ms |
11152 KB |
Output is correct |
40 |
Correct |
64 ms |
11224 KB |
Output is correct |
41 |
Correct |
59 ms |
11244 KB |
Output is correct |
42 |
Correct |
62 ms |
11348 KB |
Output is correct |
43 |
Correct |
88 ms |
11628 KB |
Output is correct |
44 |
Correct |
68 ms |
11464 KB |
Output is correct |
45 |
Correct |
63 ms |
24844 KB |
Output is correct |
46 |
Correct |
49 ms |
37140 KB |
Output is correct |
47 |
Correct |
110 ms |
18064 KB |
Output is correct |
48 |
Correct |
167 ms |
69748 KB |
Output is correct |
49 |
Correct |
176 ms |
67188 KB |
Output is correct |
50 |
Correct |
114 ms |
17996 KB |
Output is correct |
51 |
Correct |
111 ms |
18036 KB |
Output is correct |
52 |
Correct |
114 ms |
18232 KB |
Output is correct |
53 |
Correct |
122 ms |
17480 KB |
Output is correct |
54 |
Correct |
212 ms |
27952 KB |
Output is correct |
55 |
Correct |
12 ms |
5972 KB |
Output is correct |
56 |
Correct |
8 ms |
5532 KB |
Output is correct |
57 |
Correct |
42 ms |
11372 KB |
Output is correct |
58 |
Correct |
37 ms |
11152 KB |
Output is correct |
59 |
Correct |
66 ms |
37216 KB |
Output is correct |
60 |
Correct |
155 ms |
67972 KB |
Output is correct |
61 |
Correct |
144 ms |
19528 KB |
Output is correct |
62 |
Correct |
114 ms |
18160 KB |
Output is correct |
63 |
Correct |
143 ms |
18248 KB |
Output is correct |
64 |
Correct |
283 ms |
24544 KB |
Output is correct |
65 |
Correct |
266 ms |
28200 KB |
Output is correct |
66 |
Correct |
189 ms |
61636 KB |
Output is correct |
67 |
Correct |
85 ms |
18488 KB |
Output is correct |
68 |
Correct |
204 ms |
26640 KB |
Output is correct |
69 |
Correct |
224 ms |
30120 KB |
Output is correct |
70 |
Correct |
180 ms |
25816 KB |
Output is correct |