# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
399057 |
2021-05-05T08:18:20 Z |
Alex_tz307 |
Race (IOI11_race) |
C++17 |
|
452 ms |
41524 KB |
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
const int MAXN = 2e5;
const int MAXK = 1e6 + 6;
int sz[MAXN];
vector<pair<int,int>> G[MAXN];
bitset<MAXN> viz;
void find_size(int u, int parent) {
sz[u] = 1;
for (auto v : G[u])
if (v.first != parent && !viz[v.first]) {
find_size(v.first, u);
sz[u] += sz[v.first];
}
}
int find_centroid(int u, int parent, int n) {
for (auto v : G[u])
if (v.first != parent && !viz[v.first] && sz[v.first] > (n >> 1))
return find_centroid(v.first, u, n);
return u;
}
int ans = INF, k, best_prev[MAXK], best[MAXK], tree_ans;
vector<int> sums;
void min_self(int &a, int b) {
a = min(a, b);
}
void find_paths(int u, int parent, int sum, int depth) {
if (sum > k)
return;
sums.emplace_back(sum);
min_self(best[sum], depth);
min_self(tree_ans, best_prev[k - sum] + best[sum]);
if (sum == k)
return;
for (auto v : G[u])
if (v.first != parent && !viz[v.first])
find_paths(v.first, u, sum + v.second, depth + 1);
}
int solve_tree(int u) {
tree_ans = INF;
vector<int> all_sums;
for (auto v : G[u])
if (!viz[v.first]) {
find_paths(v.first, u, v.second, 1);
for (int s : sums) {
min_self(best_prev[s], best[s]);
best[s] = INF;
all_sums.emplace_back(s);
}
sums.clear();
}
for (int s : all_sums)
best_prev[s] = INF;
return tree_ans;
}
int build(int u, int parent) {
find_size(u, -1);
int c = find_centroid(u, -1, sz[u]);
viz[c] = true;
int ans = solve_tree(c);
for (auto v : G[c])
if (!viz[v.first])
ans = min(ans, build(v.first, c));
return ans;
}
int best_path(int N, int K, int H[][2], int L[]) {
for (int i = 0; i < N - 1; ++i) {
G[H[i][0]].emplace_back(H[i][1], L[i]);
G[H[i][1]].emplace_back(H[i][0], L[i]);
}
k = K;
for (int s = 1; s <= k; ++s)
best_prev[s] = best[s] = INF;
min_self(ans , build(0, -1));
if (ans == INF)
ans = -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
5020 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
3 ms |
5016 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
5024 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
5020 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
3 ms |
5016 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
5024 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
4 ms |
5068 KB |
Output is correct |
22 |
Correct |
8 ms |
12236 KB |
Output is correct |
23 |
Correct |
8 ms |
10956 KB |
Output is correct |
24 |
Correct |
8 ms |
11816 KB |
Output is correct |
25 |
Correct |
9 ms |
11596 KB |
Output is correct |
26 |
Correct |
6 ms |
7756 KB |
Output is correct |
27 |
Correct |
7 ms |
11340 KB |
Output is correct |
28 |
Correct |
5 ms |
6604 KB |
Output is correct |
29 |
Correct |
5 ms |
7628 KB |
Output is correct |
30 |
Correct |
6 ms |
7884 KB |
Output is correct |
31 |
Correct |
7 ms |
10188 KB |
Output is correct |
32 |
Correct |
8 ms |
10660 KB |
Output is correct |
33 |
Correct |
8 ms |
11212 KB |
Output is correct |
34 |
Correct |
7 ms |
9676 KB |
Output is correct |
35 |
Correct |
9 ms |
11340 KB |
Output is correct |
36 |
Correct |
8 ms |
12364 KB |
Output is correct |
37 |
Correct |
7 ms |
11340 KB |
Output is correct |
38 |
Correct |
6 ms |
9036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
5020 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
3 ms |
5016 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
5024 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
122 ms |
11728 KB |
Output is correct |
20 |
Correct |
122 ms |
11716 KB |
Output is correct |
21 |
Correct |
133 ms |
12100 KB |
Output is correct |
22 |
Correct |
128 ms |
12464 KB |
Output is correct |
23 |
Correct |
84 ms |
11912 KB |
Output is correct |
24 |
Correct |
71 ms |
11856 KB |
Output is correct |
25 |
Correct |
146 ms |
15220 KB |
Output is correct |
26 |
Correct |
114 ms |
19652 KB |
Output is correct |
27 |
Correct |
191 ms |
18688 KB |
Output is correct |
28 |
Correct |
278 ms |
33096 KB |
Output is correct |
29 |
Correct |
257 ms |
31908 KB |
Output is correct |
30 |
Correct |
183 ms |
18712 KB |
Output is correct |
31 |
Correct |
178 ms |
18628 KB |
Output is correct |
32 |
Correct |
226 ms |
18664 KB |
Output is correct |
33 |
Correct |
226 ms |
17604 KB |
Output is correct |
34 |
Correct |
178 ms |
18420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
5020 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
3 ms |
5016 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
5024 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
4 ms |
5068 KB |
Output is correct |
22 |
Correct |
8 ms |
12236 KB |
Output is correct |
23 |
Correct |
8 ms |
10956 KB |
Output is correct |
24 |
Correct |
8 ms |
11816 KB |
Output is correct |
25 |
Correct |
9 ms |
11596 KB |
Output is correct |
26 |
Correct |
6 ms |
7756 KB |
Output is correct |
27 |
Correct |
7 ms |
11340 KB |
Output is correct |
28 |
Correct |
5 ms |
6604 KB |
Output is correct |
29 |
Correct |
5 ms |
7628 KB |
Output is correct |
30 |
Correct |
6 ms |
7884 KB |
Output is correct |
31 |
Correct |
7 ms |
10188 KB |
Output is correct |
32 |
Correct |
8 ms |
10660 KB |
Output is correct |
33 |
Correct |
8 ms |
11212 KB |
Output is correct |
34 |
Correct |
7 ms |
9676 KB |
Output is correct |
35 |
Correct |
9 ms |
11340 KB |
Output is correct |
36 |
Correct |
8 ms |
12364 KB |
Output is correct |
37 |
Correct |
7 ms |
11340 KB |
Output is correct |
38 |
Correct |
6 ms |
9036 KB |
Output is correct |
39 |
Correct |
122 ms |
11728 KB |
Output is correct |
40 |
Correct |
122 ms |
11716 KB |
Output is correct |
41 |
Correct |
133 ms |
12100 KB |
Output is correct |
42 |
Correct |
128 ms |
12464 KB |
Output is correct |
43 |
Correct |
84 ms |
11912 KB |
Output is correct |
44 |
Correct |
71 ms |
11856 KB |
Output is correct |
45 |
Correct |
146 ms |
15220 KB |
Output is correct |
46 |
Correct |
114 ms |
19652 KB |
Output is correct |
47 |
Correct |
191 ms |
18688 KB |
Output is correct |
48 |
Correct |
278 ms |
33096 KB |
Output is correct |
49 |
Correct |
257 ms |
31908 KB |
Output is correct |
50 |
Correct |
183 ms |
18712 KB |
Output is correct |
51 |
Correct |
178 ms |
18628 KB |
Output is correct |
52 |
Correct |
226 ms |
18664 KB |
Output is correct |
53 |
Correct |
226 ms |
17604 KB |
Output is correct |
54 |
Correct |
178 ms |
18420 KB |
Output is correct |
55 |
Correct |
12 ms |
5800 KB |
Output is correct |
56 |
Correct |
12 ms |
5700 KB |
Output is correct |
57 |
Correct |
104 ms |
12608 KB |
Output is correct |
58 |
Correct |
45 ms |
12496 KB |
Output is correct |
59 |
Correct |
114 ms |
21184 KB |
Output is correct |
60 |
Correct |
408 ms |
41524 KB |
Output is correct |
61 |
Correct |
205 ms |
19140 KB |
Output is correct |
62 |
Correct |
214 ms |
27572 KB |
Output is correct |
63 |
Correct |
275 ms |
27588 KB |
Output is correct |
64 |
Correct |
452 ms |
24460 KB |
Output is correct |
65 |
Correct |
226 ms |
19524 KB |
Output is correct |
66 |
Correct |
422 ms |
37372 KB |
Output is correct |
67 |
Correct |
125 ms |
28852 KB |
Output is correct |
68 |
Correct |
298 ms |
28096 KB |
Output is correct |
69 |
Correct |
295 ms |
28156 KB |
Output is correct |
70 |
Correct |
270 ms |
27424 KB |
Output is correct |