# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1012996 |
2024-07-03T04:27:43 Z |
aufan |
Race (IOI11_race) |
C++17 |
|
281 ms |
76524 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int best_path(int n, int k, int h[][2], int l[]) {
vector<vector<pair<int, int>>> v(n);
for (int i = 0; i < n - 1; i++) {
int a = h[i][0], b = h[i][1], c = l[i];
v[a].push_back({b, c});
v[b].push_back({a, c});
}
int tim = -1;
vector<int> sz(n), big(n, -1), tin(n), tout(n), idx(n), dep(n);
vector<long long> d(n);
function<void(int, int)> dfs = [&](int x, int p) {
sz[x] = 1;
tin[x] = ++tim;
idx[tim] = x;
for (auto [z, c] : v[x]) {
if (z == p) continue;
d[z] = d[x] + c;
dep[z] = dep[x] + 1;
dfs(z, x);
sz[x] += sz[z];
if (big[x] == -1 || sz[z] > sz[big[x]]) big[x] = z;
}
tout[x] = tim;
};
dfs(0, 0);
int ans = INF;
map<long long, int> mp;
function<void(int, int, bool)> solve = [&](int x, int p, bool del) {
for (auto [z, c] : v[x]) {
if (z == p || z == big[x]) continue;
solve(z, x, 1);
}
if (big[x] != -1) solve(big[x], x, 0);
for (auto [z, c] : v[x]) {
if (z == p || z == big[x]) continue;
for (int tim = tin[z]; tim <= tout[z]; tim++) {
int z = idx[tim];
if (mp.count(d[x] + k - (d[z] - d[x]))) ans = min(ans, mp[d[x] + k - (d[z] - d[x])] + dep[z] - 2 * dep[x]);
}
for (int tim = tin[z]; tim <= tout[z]; tim++) {
int z = idx[tim];
if (!mp.count(d[z])) mp.insert({d[z], dep[z]});
else mp[d[z]] = min(mp[d[z]], dep[z]);
}
}
if (mp.count(d[x] + k)) ans = min(ans, mp[d[x] + k] - dep[x]);
if (!mp.count(d[x])) mp.insert({d[x], dep[x]});
else mp[d[x]] = min(mp[d[x]], dep[x]);
if (del) mp.clear();
};
solve(0, 0, 0);
if (ans == INF) ans = -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2512 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 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 |
2484 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 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 |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2512 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 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 |
2484 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2496 KB |
Output is correct |
31 |
Correct |
1 ms |
2648 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2500 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2652 KB |
Output is correct |
38 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2512 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 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 |
2484 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
87 ms |
13984 KB |
Output is correct |
20 |
Correct |
83 ms |
14920 KB |
Output is correct |
21 |
Correct |
108 ms |
14616 KB |
Output is correct |
22 |
Correct |
80 ms |
15184 KB |
Output is correct |
23 |
Correct |
108 ms |
15444 KB |
Output is correct |
24 |
Correct |
78 ms |
15192 KB |
Output is correct |
25 |
Correct |
60 ms |
25468 KB |
Output is correct |
26 |
Correct |
41 ms |
34228 KB |
Output is correct |
27 |
Correct |
111 ms |
24856 KB |
Output is correct |
28 |
Correct |
202 ms |
76524 KB |
Output is correct |
29 |
Correct |
189 ms |
74000 KB |
Output is correct |
30 |
Correct |
110 ms |
25520 KB |
Output is correct |
31 |
Correct |
110 ms |
25684 KB |
Output is correct |
32 |
Correct |
131 ms |
25524 KB |
Output is correct |
33 |
Correct |
145 ms |
24676 KB |
Output is correct |
34 |
Correct |
260 ms |
37200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2512 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 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 |
2484 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2496 KB |
Output is correct |
31 |
Correct |
1 ms |
2648 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2500 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
1 ms |
2652 KB |
Output is correct |
37 |
Correct |
1 ms |
2652 KB |
Output is correct |
38 |
Correct |
1 ms |
2652 KB |
Output is correct |
39 |
Correct |
87 ms |
13984 KB |
Output is correct |
40 |
Correct |
83 ms |
14920 KB |
Output is correct |
41 |
Correct |
108 ms |
14616 KB |
Output is correct |
42 |
Correct |
80 ms |
15184 KB |
Output is correct |
43 |
Correct |
108 ms |
15444 KB |
Output is correct |
44 |
Correct |
78 ms |
15192 KB |
Output is correct |
45 |
Correct |
60 ms |
25468 KB |
Output is correct |
46 |
Correct |
41 ms |
34228 KB |
Output is correct |
47 |
Correct |
111 ms |
24856 KB |
Output is correct |
48 |
Correct |
202 ms |
76524 KB |
Output is correct |
49 |
Correct |
189 ms |
74000 KB |
Output is correct |
50 |
Correct |
110 ms |
25520 KB |
Output is correct |
51 |
Correct |
110 ms |
25684 KB |
Output is correct |
52 |
Correct |
131 ms |
25524 KB |
Output is correct |
53 |
Correct |
145 ms |
24676 KB |
Output is correct |
54 |
Correct |
260 ms |
37200 KB |
Output is correct |
55 |
Correct |
8 ms |
3676 KB |
Output is correct |
56 |
Correct |
6 ms |
3420 KB |
Output is correct |
57 |
Correct |
55 ms |
14164 KB |
Output is correct |
58 |
Correct |
32 ms |
14916 KB |
Output is correct |
59 |
Correct |
69 ms |
40788 KB |
Output is correct |
60 |
Correct |
160 ms |
74808 KB |
Output is correct |
61 |
Correct |
130 ms |
26512 KB |
Output is correct |
62 |
Correct |
133 ms |
25496 KB |
Output is correct |
63 |
Correct |
121 ms |
25424 KB |
Output is correct |
64 |
Correct |
281 ms |
30132 KB |
Output is correct |
65 |
Correct |
256 ms |
38480 KB |
Output is correct |
66 |
Correct |
182 ms |
65104 KB |
Output is correct |
67 |
Correct |
88 ms |
26908 KB |
Output is correct |
68 |
Correct |
208 ms |
36092 KB |
Output is correct |
69 |
Correct |
181 ms |
34228 KB |
Output is correct |
70 |
Correct |
175 ms |
35360 KB |
Output is correct |