# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
998343 |
2024-06-13T16:11:52 Z |
Nailuj_217 |
Race (IOI11_race) |
C++17 |
|
139 ms |
36944 KB |
#include <bits/stdc++.h>
#define l long long
using namespace std;
#ifdef EVAL
#include "race.h"
#else
#include "grader.cpp"
#endif
const l LEN = 300005;
array<vector<pair<l, l>>, LEN> adj;
array<bool, LEN> processed;
array<l, LEN> subset;
l best;
l subsetsize(l n, l p = -1) {
l sum = 1;
for (auto [a, b]: adj[n]) {
if (!processed[a] && a != p) sum += subsetsize(a, n);
}
return subset[n] = sum;
}
l find_centroid(l n, l s, l p = -1) {
for (auto [a, b]: adj[n]) {
if (subset[a] >= s/2 && a != p && !processed[a]) return find_centroid(a, s, n);
}
return n;
}
void explore_branch(l n, map<l, l>* branch, l k, l maxk, l c = 1, l p = -1) {
if (k > maxk) return;
if (branch->find(k) != branch->end() && (*branch->find(k)).second > c) {
branch->erase(k);
branch->insert({k, c});
}
else branch->insert({k, c});
for (auto [a, b]: adj[n]) {
if (processed[a] || a == p) continue;
explore_branch(a, branch, k+b, maxk, c+1, n);
}
return;
}
l central_decomposition(l n, l k) {
l centroid = find_centroid(n, subsetsize(n));
processed[centroid] = true;
// try unordered if performance problems
map<l, l> full;
map<l, l> branch;
for (auto [a, b]: adj[centroid]) {
if (processed[a]) continue;
explore_branch(a, &branch, b, k);
if (branch.size() > full.size()) swap(branch, full);
for (auto [key, val]: branch) {
if (key > k) continue;
if (key == k) best = min(best, val);
else if (full.find(k-key) != full.end()) best = min(best, val + full[k-key]);
}
full.merge(branch);
branch.clear();
}
for (auto [a, b]: adj[centroid])
if (!processed[a])
central_decomposition(a, k);
return best;
}
int best_path(int N, int K, int H[][2], int L[]) {
if (N == 1) return -1;
adj.fill({});
processed.fill(0);
best = 1LL<<40;
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]});
}
central_decomposition(1, K);
if (best == (1LL<<40)) return -1;
return best;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
13656 KB |
Output is correct |
2 |
Correct |
2 ms |
13660 KB |
Output is correct |
3 |
Correct |
2 ms |
13656 KB |
Output is correct |
4 |
Correct |
2 ms |
13660 KB |
Output is correct |
5 |
Correct |
2 ms |
13660 KB |
Output is correct |
6 |
Correct |
3 ms |
13660 KB |
Output is correct |
7 |
Correct |
2 ms |
13768 KB |
Output is correct |
8 |
Correct |
3 ms |
13660 KB |
Output is correct |
9 |
Correct |
2 ms |
13660 KB |
Output is correct |
10 |
Correct |
2 ms |
13660 KB |
Output is correct |
11 |
Correct |
2 ms |
13660 KB |
Output is correct |
12 |
Correct |
2 ms |
13660 KB |
Output is correct |
13 |
Correct |
2 ms |
13656 KB |
Output is correct |
14 |
Correct |
2 ms |
13660 KB |
Output is correct |
15 |
Correct |
2 ms |
13660 KB |
Output is correct |
16 |
Correct |
2 ms |
13660 KB |
Output is correct |
17 |
Correct |
2 ms |
13660 KB |
Output is correct |
18 |
Correct |
2 ms |
13660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
13656 KB |
Output is correct |
2 |
Correct |
2 ms |
13660 KB |
Output is correct |
3 |
Correct |
2 ms |
13656 KB |
Output is correct |
4 |
Correct |
2 ms |
13660 KB |
Output is correct |
5 |
Correct |
2 ms |
13660 KB |
Output is correct |
6 |
Correct |
3 ms |
13660 KB |
Output is correct |
7 |
Correct |
2 ms |
13768 KB |
Output is correct |
8 |
Correct |
3 ms |
13660 KB |
Output is correct |
9 |
Correct |
2 ms |
13660 KB |
Output is correct |
10 |
Correct |
2 ms |
13660 KB |
Output is correct |
11 |
Correct |
2 ms |
13660 KB |
Output is correct |
12 |
Correct |
2 ms |
13660 KB |
Output is correct |
13 |
Correct |
2 ms |
13656 KB |
Output is correct |
14 |
Correct |
2 ms |
13660 KB |
Output is correct |
15 |
Correct |
2 ms |
13660 KB |
Output is correct |
16 |
Correct |
2 ms |
13660 KB |
Output is correct |
17 |
Correct |
2 ms |
13660 KB |
Output is correct |
18 |
Correct |
2 ms |
13660 KB |
Output is correct |
19 |
Correct |
3 ms |
13660 KB |
Output is correct |
20 |
Correct |
2 ms |
13660 KB |
Output is correct |
21 |
Correct |
5 ms |
13864 KB |
Output is correct |
22 |
Correct |
3 ms |
13660 KB |
Output is correct |
23 |
Correct |
2 ms |
13660 KB |
Output is correct |
24 |
Correct |
3 ms |
13660 KB |
Output is correct |
25 |
Correct |
3 ms |
13916 KB |
Output is correct |
26 |
Correct |
3 ms |
13660 KB |
Output is correct |
27 |
Correct |
3 ms |
13660 KB |
Output is correct |
28 |
Correct |
3 ms |
13660 KB |
Output is correct |
29 |
Correct |
3 ms |
13660 KB |
Output is correct |
30 |
Correct |
4 ms |
13916 KB |
Output is correct |
31 |
Correct |
3 ms |
13916 KB |
Output is correct |
32 |
Correct |
3 ms |
13916 KB |
Output is correct |
33 |
Correct |
3 ms |
13916 KB |
Output is correct |
34 |
Correct |
2 ms |
13660 KB |
Output is correct |
35 |
Correct |
3 ms |
13660 KB |
Output is correct |
36 |
Correct |
3 ms |
13660 KB |
Output is correct |
37 |
Correct |
3 ms |
13916 KB |
Output is correct |
38 |
Correct |
3 ms |
13928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
13656 KB |
Output is correct |
2 |
Correct |
2 ms |
13660 KB |
Output is correct |
3 |
Correct |
2 ms |
13656 KB |
Output is correct |
4 |
Correct |
2 ms |
13660 KB |
Output is correct |
5 |
Correct |
2 ms |
13660 KB |
Output is correct |
6 |
Correct |
3 ms |
13660 KB |
Output is correct |
7 |
Correct |
2 ms |
13768 KB |
Output is correct |
8 |
Correct |
3 ms |
13660 KB |
Output is correct |
9 |
Correct |
2 ms |
13660 KB |
Output is correct |
10 |
Correct |
2 ms |
13660 KB |
Output is correct |
11 |
Correct |
2 ms |
13660 KB |
Output is correct |
12 |
Correct |
2 ms |
13660 KB |
Output is correct |
13 |
Correct |
2 ms |
13656 KB |
Output is correct |
14 |
Correct |
2 ms |
13660 KB |
Output is correct |
15 |
Correct |
2 ms |
13660 KB |
Output is correct |
16 |
Correct |
2 ms |
13660 KB |
Output is correct |
17 |
Correct |
2 ms |
13660 KB |
Output is correct |
18 |
Correct |
2 ms |
13660 KB |
Output is correct |
19 |
Correct |
124 ms |
21076 KB |
Output is correct |
20 |
Correct |
122 ms |
21072 KB |
Output is correct |
21 |
Correct |
129 ms |
21076 KB |
Output is correct |
22 |
Correct |
135 ms |
21072 KB |
Output is correct |
23 |
Correct |
47 ms |
21328 KB |
Output is correct |
24 |
Correct |
48 ms |
20588 KB |
Output is correct |
25 |
Correct |
84 ms |
26196 KB |
Output is correct |
26 |
Correct |
67 ms |
26716 KB |
Output is correct |
27 |
Correct |
120 ms |
26708 KB |
Output is correct |
28 |
Correct |
139 ms |
36944 KB |
Output is correct |
29 |
Correct |
139 ms |
32592 KB |
Output is correct |
30 |
Correct |
113 ms |
26708 KB |
Output is correct |
31 |
Correct |
123 ms |
26728 KB |
Output is correct |
32 |
Incorrect |
114 ms |
26704 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
13656 KB |
Output is correct |
2 |
Correct |
2 ms |
13660 KB |
Output is correct |
3 |
Correct |
2 ms |
13656 KB |
Output is correct |
4 |
Correct |
2 ms |
13660 KB |
Output is correct |
5 |
Correct |
2 ms |
13660 KB |
Output is correct |
6 |
Correct |
3 ms |
13660 KB |
Output is correct |
7 |
Correct |
2 ms |
13768 KB |
Output is correct |
8 |
Correct |
3 ms |
13660 KB |
Output is correct |
9 |
Correct |
2 ms |
13660 KB |
Output is correct |
10 |
Correct |
2 ms |
13660 KB |
Output is correct |
11 |
Correct |
2 ms |
13660 KB |
Output is correct |
12 |
Correct |
2 ms |
13660 KB |
Output is correct |
13 |
Correct |
2 ms |
13656 KB |
Output is correct |
14 |
Correct |
2 ms |
13660 KB |
Output is correct |
15 |
Correct |
2 ms |
13660 KB |
Output is correct |
16 |
Correct |
2 ms |
13660 KB |
Output is correct |
17 |
Correct |
2 ms |
13660 KB |
Output is correct |
18 |
Correct |
2 ms |
13660 KB |
Output is correct |
19 |
Correct |
3 ms |
13660 KB |
Output is correct |
20 |
Correct |
2 ms |
13660 KB |
Output is correct |
21 |
Correct |
5 ms |
13864 KB |
Output is correct |
22 |
Correct |
3 ms |
13660 KB |
Output is correct |
23 |
Correct |
2 ms |
13660 KB |
Output is correct |
24 |
Correct |
3 ms |
13660 KB |
Output is correct |
25 |
Correct |
3 ms |
13916 KB |
Output is correct |
26 |
Correct |
3 ms |
13660 KB |
Output is correct |
27 |
Correct |
3 ms |
13660 KB |
Output is correct |
28 |
Correct |
3 ms |
13660 KB |
Output is correct |
29 |
Correct |
3 ms |
13660 KB |
Output is correct |
30 |
Correct |
4 ms |
13916 KB |
Output is correct |
31 |
Correct |
3 ms |
13916 KB |
Output is correct |
32 |
Correct |
3 ms |
13916 KB |
Output is correct |
33 |
Correct |
3 ms |
13916 KB |
Output is correct |
34 |
Correct |
2 ms |
13660 KB |
Output is correct |
35 |
Correct |
3 ms |
13660 KB |
Output is correct |
36 |
Correct |
3 ms |
13660 KB |
Output is correct |
37 |
Correct |
3 ms |
13916 KB |
Output is correct |
38 |
Correct |
3 ms |
13928 KB |
Output is correct |
39 |
Correct |
124 ms |
21076 KB |
Output is correct |
40 |
Correct |
122 ms |
21072 KB |
Output is correct |
41 |
Correct |
129 ms |
21076 KB |
Output is correct |
42 |
Correct |
135 ms |
21072 KB |
Output is correct |
43 |
Correct |
47 ms |
21328 KB |
Output is correct |
44 |
Correct |
48 ms |
20588 KB |
Output is correct |
45 |
Correct |
84 ms |
26196 KB |
Output is correct |
46 |
Correct |
67 ms |
26716 KB |
Output is correct |
47 |
Correct |
120 ms |
26708 KB |
Output is correct |
48 |
Correct |
139 ms |
36944 KB |
Output is correct |
49 |
Correct |
139 ms |
32592 KB |
Output is correct |
50 |
Correct |
113 ms |
26708 KB |
Output is correct |
51 |
Correct |
123 ms |
26728 KB |
Output is correct |
52 |
Incorrect |
114 ms |
26704 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |