# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
878970 |
2023-11-25T21:35:12 Z |
MDSPro |
Race (IOI11_race) |
C++14 |
|
670 ms |
52272 KB |
#include "race.h"
#include <vector>
#include <map>
using namespace std;
int K;
const int INF = 1e9;
vector<vector<pair<int, int>>> g;
vector<int> sz, vis;
int get_centroid(int root) {
auto sub_size = [&](auto sub_size, int x, int p) -> void {
sz[x] = 1;
for(auto [z, w]: g[x]) {
if(z != p && vis[z] == 0) {
sub_size(sub_size, z, x);
sz[x] += sz[z];
}
}
};
sub_size(sub_size, root, -1);
int n = sz[root];
auto dfs = [&](auto dfs, int x, int p) -> int {
for(auto [z, w]: g[x]) {
if(z != p && vis[z] == 0) {
if(2 * sz[z] > n) return dfs(dfs, z, x);
}
}
return x;
};
return dfs(dfs, root, -1);
}
int get(int c) {
c = get_centroid(c);
int ans = INF;
map<int, int> mp;
mp[0] = 0;
vector<pair<int, int>> collect;
auto dfs = [&](auto dfs, int x, int p, int s, int dep) -> void {
if(s > K) return;
if(mp.count(K - s)) ans = min(ans, mp[K - s] + dep);
collect.emplace_back(s, dep);
for(auto [z, w]: g[x]) {
if(z != p && vis[z] == 0) {
dfs(dfs, z, x, s + w, dep + 1);
}
}
};
vis[c] = 1;
for(auto [z, w]: g[c]) {
if(vis[z] == 0) {
collect.clear();
dfs(dfs, z, c, w, 1);
for(auto [s, dep]: collect) {
if(!mp.count(s) || mp[s] > dep) {
mp[s] = dep;
}
}
ans = min(ans, get(z));
}
}
return ans;
}
int best_path(int N, int K, int H[][2], int L[]) {
::K = K;
g.resize(N);
sz.resize(N);
vis.resize(N);
for(int i = 0; i < N - 1; ++i) {
int x = H[i][0], y = H[i][1], w = L[i];
g[x].emplace_back(y, w);
g[y].emplace_back(x, w);
}
int ans = get(0);
if(ans == INF) return -1;
return ans;
}
Compilation message
race.cpp: In lambda function:
race.cpp:15:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
15 | for(auto [z, w]: g[x]) {
| ^
race.cpp: In lambda function:
race.cpp:27:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
27 | for(auto [z, w]: g[x]) {
| ^
race.cpp: In lambda function:
race.cpp:53:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
53 | for(auto [z, w]: g[x]) {
| ^
race.cpp: In function 'int get(int)':
race.cpp:61:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
61 | for(auto [z, w]: g[c]) {
| ^
race.cpp:66:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
66 | for(auto [s, dep]: collect) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2480 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2476 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2480 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2476 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2524 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2492 KB |
Output is correct |
25 |
Correct |
2 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
2 ms |
2396 KB |
Output is correct |
29 |
Correct |
2 ms |
2392 KB |
Output is correct |
30 |
Correct |
2 ms |
2392 KB |
Output is correct |
31 |
Correct |
2 ms |
2396 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
2 ms |
2392 KB |
Output is correct |
38 |
Correct |
2 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2480 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2476 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
132 ms |
11224 KB |
Output is correct |
20 |
Correct |
128 ms |
11088 KB |
Output is correct |
21 |
Correct |
148 ms |
11472 KB |
Output is correct |
22 |
Correct |
127 ms |
11724 KB |
Output is correct |
23 |
Correct |
61 ms |
11348 KB |
Output is correct |
24 |
Correct |
54 ms |
11100 KB |
Output is correct |
25 |
Correct |
99 ms |
12844 KB |
Output is correct |
26 |
Correct |
87 ms |
17480 KB |
Output is correct |
27 |
Correct |
147 ms |
21996 KB |
Output is correct |
28 |
Correct |
174 ms |
28756 KB |
Output is correct |
29 |
Correct |
196 ms |
28284 KB |
Output is correct |
30 |
Correct |
145 ms |
21956 KB |
Output is correct |
31 |
Correct |
137 ms |
22008 KB |
Output is correct |
32 |
Correct |
142 ms |
21968 KB |
Output is correct |
33 |
Correct |
193 ms |
20864 KB |
Output is correct |
34 |
Correct |
118 ms |
21464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2480 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2476 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2524 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2492 KB |
Output is correct |
25 |
Correct |
2 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
2 ms |
2396 KB |
Output is correct |
29 |
Correct |
2 ms |
2392 KB |
Output is correct |
30 |
Correct |
2 ms |
2392 KB |
Output is correct |
31 |
Correct |
2 ms |
2396 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2652 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
2 ms |
2392 KB |
Output is correct |
38 |
Correct |
2 ms |
2392 KB |
Output is correct |
39 |
Correct |
132 ms |
11224 KB |
Output is correct |
40 |
Correct |
128 ms |
11088 KB |
Output is correct |
41 |
Correct |
148 ms |
11472 KB |
Output is correct |
42 |
Correct |
127 ms |
11724 KB |
Output is correct |
43 |
Correct |
61 ms |
11348 KB |
Output is correct |
44 |
Correct |
54 ms |
11100 KB |
Output is correct |
45 |
Correct |
99 ms |
12844 KB |
Output is correct |
46 |
Correct |
87 ms |
17480 KB |
Output is correct |
47 |
Correct |
147 ms |
21996 KB |
Output is correct |
48 |
Correct |
174 ms |
28756 KB |
Output is correct |
49 |
Correct |
196 ms |
28284 KB |
Output is correct |
50 |
Correct |
145 ms |
21956 KB |
Output is correct |
51 |
Correct |
137 ms |
22008 KB |
Output is correct |
52 |
Correct |
142 ms |
21968 KB |
Output is correct |
53 |
Correct |
193 ms |
20864 KB |
Output is correct |
54 |
Correct |
118 ms |
21464 KB |
Output is correct |
55 |
Correct |
14 ms |
3416 KB |
Output is correct |
56 |
Correct |
10 ms |
3416 KB |
Output is correct |
57 |
Correct |
111 ms |
11732 KB |
Output is correct |
58 |
Correct |
34 ms |
10796 KB |
Output is correct |
59 |
Correct |
243 ms |
24476 KB |
Output is correct |
60 |
Correct |
670 ms |
52272 KB |
Output is correct |
61 |
Correct |
235 ms |
22352 KB |
Output is correct |
62 |
Correct |
202 ms |
22100 KB |
Output is correct |
63 |
Correct |
238 ms |
22344 KB |
Output is correct |
64 |
Correct |
637 ms |
31528 KB |
Output is correct |
65 |
Correct |
125 ms |
22916 KB |
Output is correct |
66 |
Correct |
473 ms |
28916 KB |
Output is correct |
67 |
Correct |
86 ms |
22720 KB |
Output is correct |
68 |
Correct |
272 ms |
26432 KB |
Output is correct |
69 |
Correct |
318 ms |
26452 KB |
Output is correct |
70 |
Correct |
246 ms |
25568 KB |
Output is correct |