# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
730516 |
2023-04-26T04:36:38 Z |
t6twotwo |
Race (IOI11_race) |
C++17 |
|
484 ms |
104680 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
int best_path(int N, int K, int H[][2], int L[]) {
vector<vector<pair<int, int>>> adj(N);
for (int i = 0; i < N - 1; i++) {
adj[H[i][0]].emplace_back(H[i][1], L[i]);
adj[H[i][1]].emplace_back(H[i][0], L[i]);
}
int ans = N;
vector<set<pair<int64_t, int>>> s(N);
auto dfs = [&](auto dfs, int x, int p, int64_t dis, int dep) -> void {
s[x].emplace(dis, dep);
for (auto [y, z] : adj[x]) {
if (y == p) {
continue;
}
dfs(dfs, y, x, dis + z, dep + 1);
if (s[x].size() < s[y].size()) {
swap(s[x], s[y]);
}
for (auto [len, cnt] : s[y]) {
int64_t q = K - len + 2 * dis;
auto it = s[x].lower_bound({q, 0});
if (it != s[x].end() && (*it).first == q) {
ans = min(ans, (*it).second + cnt - 2 * dep);
}
}
s[x].insert(s[y].begin(), s[y].end());
}
};
dfs(dfs, 0, -1, 0, 0);
if (ans == N) {
ans = -1;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
2 ms |
596 KB |
Output is correct |
24 |
Correct |
2 ms |
596 KB |
Output is correct |
25 |
Correct |
1 ms |
596 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
596 KB |
Output is correct |
29 |
Correct |
2 ms |
596 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
1 ms |
596 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |
33 |
Correct |
2 ms |
596 KB |
Output is correct |
34 |
Correct |
1 ms |
596 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
36 |
Correct |
1 ms |
596 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
155 ms |
32556 KB |
Output is correct |
20 |
Correct |
139 ms |
32592 KB |
Output is correct |
21 |
Correct |
141 ms |
31940 KB |
Output is correct |
22 |
Correct |
143 ms |
30476 KB |
Output is correct |
23 |
Correct |
180 ms |
44900 KB |
Output is correct |
24 |
Correct |
167 ms |
31476 KB |
Output is correct |
25 |
Correct |
133 ms |
36188 KB |
Output is correct |
26 |
Correct |
80 ms |
41376 KB |
Output is correct |
27 |
Correct |
184 ms |
46448 KB |
Output is correct |
28 |
Correct |
292 ms |
82356 KB |
Output is correct |
29 |
Correct |
286 ms |
80692 KB |
Output is correct |
30 |
Correct |
182 ms |
46488 KB |
Output is correct |
31 |
Correct |
206 ms |
46364 KB |
Output is correct |
32 |
Correct |
296 ms |
46364 KB |
Output is correct |
33 |
Correct |
230 ms |
48192 KB |
Output is correct |
34 |
Correct |
334 ms |
80148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
2 ms |
596 KB |
Output is correct |
24 |
Correct |
2 ms |
596 KB |
Output is correct |
25 |
Correct |
1 ms |
596 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
596 KB |
Output is correct |
29 |
Correct |
2 ms |
596 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
1 ms |
596 KB |
Output is correct |
32 |
Correct |
2 ms |
596 KB |
Output is correct |
33 |
Correct |
2 ms |
596 KB |
Output is correct |
34 |
Correct |
1 ms |
596 KB |
Output is correct |
35 |
Correct |
1 ms |
596 KB |
Output is correct |
36 |
Correct |
1 ms |
596 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Correct |
1 ms |
596 KB |
Output is correct |
39 |
Correct |
155 ms |
32556 KB |
Output is correct |
40 |
Correct |
139 ms |
32592 KB |
Output is correct |
41 |
Correct |
141 ms |
31940 KB |
Output is correct |
42 |
Correct |
143 ms |
30476 KB |
Output is correct |
43 |
Correct |
180 ms |
44900 KB |
Output is correct |
44 |
Correct |
167 ms |
31476 KB |
Output is correct |
45 |
Correct |
133 ms |
36188 KB |
Output is correct |
46 |
Correct |
80 ms |
41376 KB |
Output is correct |
47 |
Correct |
184 ms |
46448 KB |
Output is correct |
48 |
Correct |
292 ms |
82356 KB |
Output is correct |
49 |
Correct |
286 ms |
80692 KB |
Output is correct |
50 |
Correct |
182 ms |
46488 KB |
Output is correct |
51 |
Correct |
206 ms |
46364 KB |
Output is correct |
52 |
Correct |
296 ms |
46364 KB |
Output is correct |
53 |
Correct |
230 ms |
48192 KB |
Output is correct |
54 |
Correct |
334 ms |
80148 KB |
Output is correct |
55 |
Correct |
14 ms |
4180 KB |
Output is correct |
56 |
Correct |
13 ms |
3028 KB |
Output is correct |
57 |
Correct |
90 ms |
27308 KB |
Output is correct |
58 |
Correct |
45 ms |
18632 KB |
Output is correct |
59 |
Correct |
79 ms |
41344 KB |
Output is correct |
60 |
Correct |
272 ms |
81452 KB |
Output is correct |
61 |
Correct |
249 ms |
52016 KB |
Output is correct |
62 |
Correct |
185 ms |
46440 KB |
Output is correct |
63 |
Correct |
264 ms |
46500 KB |
Output is correct |
64 |
Correct |
467 ms |
104680 KB |
Output is correct |
65 |
Correct |
484 ms |
95916 KB |
Output is correct |
66 |
Correct |
310 ms |
77076 KB |
Output is correct |
67 |
Correct |
190 ms |
37420 KB |
Output is correct |
68 |
Correct |
335 ms |
61052 KB |
Output is correct |
69 |
Correct |
370 ms |
66868 KB |
Output is correct |
70 |
Correct |
318 ms |
58460 KB |
Output is correct |