# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
998166 |
2024-06-13T11:11:00 Z |
The_Samurai |
Race (IOI11_race) |
C++17 |
|
3000 ms |
37996 KB |
#include "bits/stdc++.h"
#include "race.h"
using namespace std;
using ll = long long;
const int inf = 1e9, N = 2e5 + 5;
int ans = inf, k;
vector<vector<pair<int, int>>> g(N);
vector<int> par(N, -1), heavy(N), height2(N);
vector<ll> height(N);
vector<set<pair<ll, int>>> st(N);
/*
height[heavy[u]] - height[v] = k +
height[v] - height[u] = k?????
height[heavy[u]] - k - height[u] = height[v]
*/
int dfs(int u) {
heavy[u] = u;
int size = 1, max_child_size = 0;
for (auto [v, w]: g[u]) {
if (par[u] == v) continue;
height[v] = height[u] + w;
height2[v] = height2[u] + 1;
par[v] = u;
int child_size = dfs(v);
if (child_size > max_child_size) {
heavy[u] = heavy[v];
max_child_size = child_size;
}
size += child_size;
}
return size;
}
void dfs2(int u) {
for (auto [v, w]: g[u]) {
if (par[u] == v) continue;
dfs2(v);
}
multiset<pair<ll, int>> shit;
for (auto it: st[heavy[u]]) shit.insert(it);
// cout << u << ' ' << heavy[u] << endl;
for (auto [v, w]: g[u]) {
if (par[u] == v or heavy[u] == heavy[v]) continue;
for (auto it: st[heavy[v]]) {
st[heavy[u]].insert(it);
shit.insert(it);
}
}
// if (u == 1) {
// for (auto it: shit) {
// cout << it.first << ' ' << it.second << endl;
// }
// }
for (auto [v, w]: g[u]) {
if (par[u] == v or heavy[u] == heavy[v]) continue;
for (auto it: st[heavy[v]]) {
shit.erase(shit.find(it));
}
for (auto it: st[heavy[v]]) {
ll need = k - (it.first - height[u]) + height[u];
auto it2 = shit.lower_bound(make_pair(need, 0));
if (it2 != shit.end() and it2->first == need) {
ans = min(ans, it2->second + it.second - 2 * height2[u]);
}
}
for (auto it: st[heavy[v]]) {
shit.insert(it);
}
st[heavy[v]].clear();
}
st[heavy[u]].emplace(height[u], height2[u]);
ll search = k + height[u];
auto it = st[heavy[u]].lower_bound(make_pair(search, 0));
if (it != st[heavy[u]].end() and it->first == search) {
ans = min(ans, it->second - height2[u]);
}
}
int best_path(int n, int K, int H[][2], int L[]) {
k = K;
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]);
}
// change it
dfs(0);
dfs2(0);
return ans == inf ? -1 : ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
20568 KB |
Output is correct |
2 |
Correct |
4 ms |
20316 KB |
Output is correct |
3 |
Correct |
5 ms |
20316 KB |
Output is correct |
4 |
Correct |
5 ms |
20316 KB |
Output is correct |
5 |
Correct |
5 ms |
20316 KB |
Output is correct |
6 |
Correct |
5 ms |
20316 KB |
Output is correct |
7 |
Correct |
5 ms |
20316 KB |
Output is correct |
8 |
Correct |
5 ms |
20316 KB |
Output is correct |
9 |
Correct |
5 ms |
20316 KB |
Output is correct |
10 |
Correct |
6 ms |
20312 KB |
Output is correct |
11 |
Correct |
5 ms |
20316 KB |
Output is correct |
12 |
Correct |
5 ms |
20404 KB |
Output is correct |
13 |
Correct |
7 ms |
20572 KB |
Output is correct |
14 |
Correct |
7 ms |
20316 KB |
Output is correct |
15 |
Correct |
5 ms |
20380 KB |
Output is correct |
16 |
Correct |
5 ms |
20316 KB |
Output is correct |
17 |
Correct |
6 ms |
20532 KB |
Output is correct |
18 |
Correct |
8 ms |
20316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
20568 KB |
Output is correct |
2 |
Correct |
4 ms |
20316 KB |
Output is correct |
3 |
Correct |
5 ms |
20316 KB |
Output is correct |
4 |
Correct |
5 ms |
20316 KB |
Output is correct |
5 |
Correct |
5 ms |
20316 KB |
Output is correct |
6 |
Correct |
5 ms |
20316 KB |
Output is correct |
7 |
Correct |
5 ms |
20316 KB |
Output is correct |
8 |
Correct |
5 ms |
20316 KB |
Output is correct |
9 |
Correct |
5 ms |
20316 KB |
Output is correct |
10 |
Correct |
6 ms |
20312 KB |
Output is correct |
11 |
Correct |
5 ms |
20316 KB |
Output is correct |
12 |
Correct |
5 ms |
20404 KB |
Output is correct |
13 |
Correct |
7 ms |
20572 KB |
Output is correct |
14 |
Correct |
7 ms |
20316 KB |
Output is correct |
15 |
Correct |
5 ms |
20380 KB |
Output is correct |
16 |
Correct |
5 ms |
20316 KB |
Output is correct |
17 |
Correct |
6 ms |
20532 KB |
Output is correct |
18 |
Correct |
8 ms |
20316 KB |
Output is correct |
19 |
Correct |
5 ms |
20316 KB |
Output is correct |
20 |
Correct |
5 ms |
20456 KB |
Output is correct |
21 |
Correct |
6 ms |
20572 KB |
Output is correct |
22 |
Correct |
6 ms |
20568 KB |
Output is correct |
23 |
Correct |
7 ms |
20572 KB |
Output is correct |
24 |
Correct |
6 ms |
20640 KB |
Output is correct |
25 |
Correct |
7 ms |
20572 KB |
Output is correct |
26 |
Correct |
6 ms |
20572 KB |
Output is correct |
27 |
Correct |
6 ms |
20572 KB |
Output is correct |
28 |
Correct |
7 ms |
20572 KB |
Output is correct |
29 |
Correct |
8 ms |
20572 KB |
Output is correct |
30 |
Correct |
6 ms |
20516 KB |
Output is correct |
31 |
Correct |
7 ms |
20572 KB |
Output is correct |
32 |
Correct |
6 ms |
20552 KB |
Output is correct |
33 |
Correct |
7 ms |
20572 KB |
Output is correct |
34 |
Correct |
13 ms |
20572 KB |
Output is correct |
35 |
Correct |
19 ms |
20572 KB |
Output is correct |
36 |
Correct |
15 ms |
20572 KB |
Output is correct |
37 |
Correct |
11 ms |
20568 KB |
Output is correct |
38 |
Correct |
9 ms |
20568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
20568 KB |
Output is correct |
2 |
Correct |
4 ms |
20316 KB |
Output is correct |
3 |
Correct |
5 ms |
20316 KB |
Output is correct |
4 |
Correct |
5 ms |
20316 KB |
Output is correct |
5 |
Correct |
5 ms |
20316 KB |
Output is correct |
6 |
Correct |
5 ms |
20316 KB |
Output is correct |
7 |
Correct |
5 ms |
20316 KB |
Output is correct |
8 |
Correct |
5 ms |
20316 KB |
Output is correct |
9 |
Correct |
5 ms |
20316 KB |
Output is correct |
10 |
Correct |
6 ms |
20312 KB |
Output is correct |
11 |
Correct |
5 ms |
20316 KB |
Output is correct |
12 |
Correct |
5 ms |
20404 KB |
Output is correct |
13 |
Correct |
7 ms |
20572 KB |
Output is correct |
14 |
Correct |
7 ms |
20316 KB |
Output is correct |
15 |
Correct |
5 ms |
20380 KB |
Output is correct |
16 |
Correct |
5 ms |
20316 KB |
Output is correct |
17 |
Correct |
6 ms |
20532 KB |
Output is correct |
18 |
Correct |
8 ms |
20316 KB |
Output is correct |
19 |
Correct |
190 ms |
26964 KB |
Output is correct |
20 |
Correct |
198 ms |
27220 KB |
Output is correct |
21 |
Correct |
167 ms |
26708 KB |
Output is correct |
22 |
Correct |
155 ms |
27216 KB |
Output is correct |
23 |
Correct |
273 ms |
27472 KB |
Output is correct |
24 |
Correct |
144 ms |
27144 KB |
Output is correct |
25 |
Execution timed out |
3015 ms |
37996 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
20568 KB |
Output is correct |
2 |
Correct |
4 ms |
20316 KB |
Output is correct |
3 |
Correct |
5 ms |
20316 KB |
Output is correct |
4 |
Correct |
5 ms |
20316 KB |
Output is correct |
5 |
Correct |
5 ms |
20316 KB |
Output is correct |
6 |
Correct |
5 ms |
20316 KB |
Output is correct |
7 |
Correct |
5 ms |
20316 KB |
Output is correct |
8 |
Correct |
5 ms |
20316 KB |
Output is correct |
9 |
Correct |
5 ms |
20316 KB |
Output is correct |
10 |
Correct |
6 ms |
20312 KB |
Output is correct |
11 |
Correct |
5 ms |
20316 KB |
Output is correct |
12 |
Correct |
5 ms |
20404 KB |
Output is correct |
13 |
Correct |
7 ms |
20572 KB |
Output is correct |
14 |
Correct |
7 ms |
20316 KB |
Output is correct |
15 |
Correct |
5 ms |
20380 KB |
Output is correct |
16 |
Correct |
5 ms |
20316 KB |
Output is correct |
17 |
Correct |
6 ms |
20532 KB |
Output is correct |
18 |
Correct |
8 ms |
20316 KB |
Output is correct |
19 |
Correct |
5 ms |
20316 KB |
Output is correct |
20 |
Correct |
5 ms |
20456 KB |
Output is correct |
21 |
Correct |
6 ms |
20572 KB |
Output is correct |
22 |
Correct |
6 ms |
20568 KB |
Output is correct |
23 |
Correct |
7 ms |
20572 KB |
Output is correct |
24 |
Correct |
6 ms |
20640 KB |
Output is correct |
25 |
Correct |
7 ms |
20572 KB |
Output is correct |
26 |
Correct |
6 ms |
20572 KB |
Output is correct |
27 |
Correct |
6 ms |
20572 KB |
Output is correct |
28 |
Correct |
7 ms |
20572 KB |
Output is correct |
29 |
Correct |
8 ms |
20572 KB |
Output is correct |
30 |
Correct |
6 ms |
20516 KB |
Output is correct |
31 |
Correct |
7 ms |
20572 KB |
Output is correct |
32 |
Correct |
6 ms |
20552 KB |
Output is correct |
33 |
Correct |
7 ms |
20572 KB |
Output is correct |
34 |
Correct |
13 ms |
20572 KB |
Output is correct |
35 |
Correct |
19 ms |
20572 KB |
Output is correct |
36 |
Correct |
15 ms |
20572 KB |
Output is correct |
37 |
Correct |
11 ms |
20568 KB |
Output is correct |
38 |
Correct |
9 ms |
20568 KB |
Output is correct |
39 |
Correct |
190 ms |
26964 KB |
Output is correct |
40 |
Correct |
198 ms |
27220 KB |
Output is correct |
41 |
Correct |
167 ms |
26708 KB |
Output is correct |
42 |
Correct |
155 ms |
27216 KB |
Output is correct |
43 |
Correct |
273 ms |
27472 KB |
Output is correct |
44 |
Correct |
144 ms |
27144 KB |
Output is correct |
45 |
Execution timed out |
3015 ms |
37996 KB |
Time limit exceeded |
46 |
Halted |
0 ms |
0 KB |
- |