# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
703629 |
2023-02-27T21:44:54 Z |
boyliguanhan |
Race (IOI11_race) |
C++17 |
|
1136 ms |
42388 KB |
#include "race.h"
#include<vector>
#include<utility>
#include<map>
#include<algorithm>
using namespace std;
#define int long long
#define inf 1000000000
vector<pair<int, int>> adj[200100];
int ans = inf, rt, k, sz[200100];
bool vis[200100];
map<int, int> cache;
void csz(int n, int p, int tot) {
int ms = 0;
sz[n] = 1;
for (auto &i : adj[n])
if (i.first != p && !vis[i.first])
csz(i.first, n, tot), ms = max(ms, sz[i.first]), sz[n] += sz[i.first];
if (ms <= tot / 2 && sz[n] >= tot / 2)
rt = n;
}
void cans(int n, int p, int d1, int d2) {
if (d1 > k)
return;
if (cache.count(k - d1))
ans = min(ans, d2 + cache[k - d1]);
for (auto &i : adj[n])
if (i.first != p && !vis[i.first])
cans(i.first, n, d1 + i.second, d2 + 1);
}
void ccache(int n, int p, int d1, int d2) {
if (d1 > k)
return;
if (cache.count(d1))
cache[d1] = min(cache[d1], d2);
else
cache[d1] = d2;
for (auto& i : adj[n])
if (i.first != p && !vis[i.first])
ccache(i.first, n, d1 + i.second, d2 + 1);
}
void decomp(int n, int tot) {
vector<int> v;
cache.clear();
cache[0];
csz(n, -1, tot);
n = rt;
vis[n] = 1;
for (auto &i : adj[n]) {
if (!vis[i.first])
cans(i.first, -1, i.second, 1), ccache(i.first, -1, i.second, 1);
v.push_back(sz[i.first]);
}
int x = 0;
for (auto &i : adj[n]) {
if (!vis[i.first])
decomp(i.first, v[x]);
x++;
}
}
signed best_path(signed N, signed K, signed H[][2], signed L[]) {
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] });
k = K;
decomp(1, N);
return ans == inf ? -1 : ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
5036 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
5036 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
5076 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5016 KB |
Output is correct |
24 |
Correct |
5 ms |
5016 KB |
Output is correct |
25 |
Correct |
4 ms |
5144 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5124 KB |
Output is correct |
29 |
Correct |
4 ms |
5140 KB |
Output is correct |
30 |
Correct |
4 ms |
5140 KB |
Output is correct |
31 |
Correct |
4 ms |
5076 KB |
Output is correct |
32 |
Correct |
4 ms |
5076 KB |
Output is correct |
33 |
Correct |
4 ms |
5076 KB |
Output is correct |
34 |
Correct |
3 ms |
5076 KB |
Output is correct |
35 |
Correct |
4 ms |
5076 KB |
Output is correct |
36 |
Correct |
4 ms |
5016 KB |
Output is correct |
37 |
Correct |
3 ms |
5116 KB |
Output is correct |
38 |
Correct |
4 ms |
5140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
5036 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
242 ms |
12148 KB |
Output is correct |
20 |
Correct |
252 ms |
12040 KB |
Output is correct |
21 |
Correct |
248 ms |
12060 KB |
Output is correct |
22 |
Correct |
259 ms |
12216 KB |
Output is correct |
23 |
Correct |
72 ms |
12460 KB |
Output is correct |
24 |
Correct |
79 ms |
11724 KB |
Output is correct |
25 |
Correct |
136 ms |
18764 KB |
Output is correct |
26 |
Correct |
101 ms |
19748 KB |
Output is correct |
27 |
Correct |
190 ms |
19784 KB |
Output is correct |
28 |
Correct |
283 ms |
33100 KB |
Output is correct |
29 |
Correct |
270 ms |
27908 KB |
Output is correct |
30 |
Correct |
188 ms |
19792 KB |
Output is correct |
31 |
Correct |
192 ms |
19788 KB |
Output is correct |
32 |
Correct |
216 ms |
19904 KB |
Output is correct |
33 |
Correct |
255 ms |
18580 KB |
Output is correct |
34 |
Correct |
161 ms |
18508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
5036 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
5076 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5016 KB |
Output is correct |
24 |
Correct |
5 ms |
5016 KB |
Output is correct |
25 |
Correct |
4 ms |
5144 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5124 KB |
Output is correct |
29 |
Correct |
4 ms |
5140 KB |
Output is correct |
30 |
Correct |
4 ms |
5140 KB |
Output is correct |
31 |
Correct |
4 ms |
5076 KB |
Output is correct |
32 |
Correct |
4 ms |
5076 KB |
Output is correct |
33 |
Correct |
4 ms |
5076 KB |
Output is correct |
34 |
Correct |
3 ms |
5076 KB |
Output is correct |
35 |
Correct |
4 ms |
5076 KB |
Output is correct |
36 |
Correct |
4 ms |
5016 KB |
Output is correct |
37 |
Correct |
3 ms |
5116 KB |
Output is correct |
38 |
Correct |
4 ms |
5140 KB |
Output is correct |
39 |
Correct |
242 ms |
12148 KB |
Output is correct |
40 |
Correct |
252 ms |
12040 KB |
Output is correct |
41 |
Correct |
248 ms |
12060 KB |
Output is correct |
42 |
Correct |
259 ms |
12216 KB |
Output is correct |
43 |
Correct |
72 ms |
12460 KB |
Output is correct |
44 |
Correct |
79 ms |
11724 KB |
Output is correct |
45 |
Correct |
136 ms |
18764 KB |
Output is correct |
46 |
Correct |
101 ms |
19748 KB |
Output is correct |
47 |
Correct |
190 ms |
19784 KB |
Output is correct |
48 |
Correct |
283 ms |
33100 KB |
Output is correct |
49 |
Correct |
270 ms |
27908 KB |
Output is correct |
50 |
Correct |
188 ms |
19792 KB |
Output is correct |
51 |
Correct |
192 ms |
19788 KB |
Output is correct |
52 |
Correct |
216 ms |
19904 KB |
Output is correct |
53 |
Correct |
255 ms |
18580 KB |
Output is correct |
54 |
Correct |
161 ms |
18508 KB |
Output is correct |
55 |
Correct |
25 ms |
5972 KB |
Output is correct |
56 |
Correct |
18 ms |
5784 KB |
Output is correct |
57 |
Correct |
156 ms |
13980 KB |
Output is correct |
58 |
Correct |
59 ms |
15872 KB |
Output is correct |
59 |
Correct |
274 ms |
25492 KB |
Output is correct |
60 |
Correct |
810 ms |
42388 KB |
Output is correct |
61 |
Correct |
265 ms |
23220 KB |
Output is correct |
62 |
Correct |
283 ms |
22996 KB |
Output is correct |
63 |
Correct |
327 ms |
22972 KB |
Output is correct |
64 |
Correct |
1136 ms |
28860 KB |
Output is correct |
65 |
Correct |
225 ms |
23244 KB |
Output is correct |
66 |
Correct |
523 ms |
35220 KB |
Output is correct |
67 |
Correct |
135 ms |
25388 KB |
Output is correct |
68 |
Correct |
394 ms |
27700 KB |
Output is correct |
69 |
Correct |
355 ms |
27584 KB |
Output is correct |
70 |
Correct |
325 ms |
26632 KB |
Output is correct |