# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1079027 |
2024-08-28T09:34:23 Z |
coolboy19521 |
Race (IOI11_race) |
C++17 |
|
2630 ms |
242408 KB |
#include "race.h"
#include "bits/stdc++.h"
#define ll long long
using namespace std;
const int sz = 2e5 + 10;
vector<pair<int,int>> aj[sz];
map<ll,int> mc[sz], ban;
int ts[sz], k, r;
int uk(int v, int p = -1) {
ts[v] = 1;
for (auto& [u, _] : aj[v]) if (u != p)
ts[v] += uk(u, v);
return ts[v];
}
int fC(int v, int p = -1) {
for (auto& [u, _] : aj[v])
if (u != p && !ban[u])
if (ts[u] > ts[v] / 2) {
ts[v] -= ts[u];
ts[u] += ts[v];
return fC(u, v);
}
return v;
}
void marj(int v, int u) {
for (auto& [tr, mn] : mc[u])
if (mc[v].find(tr) != end(mc[v]))
mc[v][tr] = min(mc[v][tr], mn);
else mc[v][tr] = mn;
mc[u].clear();
}
void dfs(int v, int p, int l, int d = 1) {
mc[v][l] = d;
for (auto& [u, w] : aj[v])
if (u != p && !ban[u]) {
dfs(u, v, l + w, d + 1);
if (mc[v].size() < mc[u].size())
mc[v].swap(mc[u]);
marj(v, u);
}
}
void cD(int v) {
v = fC(v);
mc[v].clear();
for (auto& [u, w] : aj[v]) if (!ban[u]) {
dfs(u, v, w);
if (mc[v].size() < mc[u].size())
mc[v].swap(mc[u]);
for (auto& [tr, mn] : mc[u])
if (mc[v].find(k - tr) != end(mc[v]))
r = min(r, mn + mc[v][k - tr]);
marj(v, u);
}
if (mc[v].find(k) != end(mc[v]))
r = min(r, mc[v][k]);
ban[v] = 1;
for (auto& [u, _] : aj[v])
if (!ban[u]) cD(u);
}
int best_path(int N, int K, int H[][2], int L[]) {
if (1 == N) {
if (0 == K) return 0;
else return -1;
}
for (int i = 0; i < N - 1; i ++) {
int a = H[i][0], b = H[i][1];
aj[a].emplace_back(b, L[i]);
aj[b].emplace_back(a, L[i]);
}
r = N, k = K;
uk(0);
cD(0);
return r < N ? r : -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14684 KB |
Output is correct |
2 |
Correct |
3 ms |
14684 KB |
Output is correct |
3 |
Correct |
4 ms |
14684 KB |
Output is correct |
4 |
Correct |
4 ms |
14684 KB |
Output is correct |
5 |
Correct |
3 ms |
14680 KB |
Output is correct |
6 |
Correct |
3 ms |
14684 KB |
Output is correct |
7 |
Correct |
4 ms |
14916 KB |
Output is correct |
8 |
Correct |
4 ms |
14684 KB |
Output is correct |
9 |
Correct |
3 ms |
14908 KB |
Output is correct |
10 |
Correct |
3 ms |
14684 KB |
Output is correct |
11 |
Correct |
3 ms |
14684 KB |
Output is correct |
12 |
Correct |
3 ms |
14684 KB |
Output is correct |
13 |
Correct |
4 ms |
14680 KB |
Output is correct |
14 |
Correct |
4 ms |
14684 KB |
Output is correct |
15 |
Correct |
4 ms |
14684 KB |
Output is correct |
16 |
Correct |
3 ms |
14684 KB |
Output is correct |
17 |
Correct |
3 ms |
14684 KB |
Output is correct |
18 |
Correct |
3 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14684 KB |
Output is correct |
2 |
Correct |
3 ms |
14684 KB |
Output is correct |
3 |
Correct |
4 ms |
14684 KB |
Output is correct |
4 |
Correct |
4 ms |
14684 KB |
Output is correct |
5 |
Correct |
3 ms |
14680 KB |
Output is correct |
6 |
Correct |
3 ms |
14684 KB |
Output is correct |
7 |
Correct |
4 ms |
14916 KB |
Output is correct |
8 |
Correct |
4 ms |
14684 KB |
Output is correct |
9 |
Correct |
3 ms |
14908 KB |
Output is correct |
10 |
Correct |
3 ms |
14684 KB |
Output is correct |
11 |
Correct |
3 ms |
14684 KB |
Output is correct |
12 |
Correct |
3 ms |
14684 KB |
Output is correct |
13 |
Correct |
4 ms |
14680 KB |
Output is correct |
14 |
Correct |
4 ms |
14684 KB |
Output is correct |
15 |
Correct |
4 ms |
14684 KB |
Output is correct |
16 |
Correct |
3 ms |
14684 KB |
Output is correct |
17 |
Correct |
3 ms |
14684 KB |
Output is correct |
18 |
Correct |
3 ms |
14684 KB |
Output is correct |
19 |
Correct |
3 ms |
14684 KB |
Output is correct |
20 |
Correct |
3 ms |
14684 KB |
Output is correct |
21 |
Correct |
6 ms |
15196 KB |
Output is correct |
22 |
Correct |
6 ms |
15196 KB |
Output is correct |
23 |
Correct |
6 ms |
15192 KB |
Output is correct |
24 |
Correct |
5 ms |
15196 KB |
Output is correct |
25 |
Correct |
6 ms |
15192 KB |
Output is correct |
26 |
Correct |
5 ms |
15196 KB |
Output is correct |
27 |
Correct |
4 ms |
14936 KB |
Output is correct |
28 |
Correct |
6 ms |
15196 KB |
Output is correct |
29 |
Correct |
6 ms |
15196 KB |
Output is correct |
30 |
Correct |
6 ms |
15196 KB |
Output is correct |
31 |
Correct |
8 ms |
15196 KB |
Output is correct |
32 |
Correct |
6 ms |
15192 KB |
Output is correct |
33 |
Correct |
6 ms |
15196 KB |
Output is correct |
34 |
Correct |
6 ms |
15288 KB |
Output is correct |
35 |
Correct |
6 ms |
15196 KB |
Output is correct |
36 |
Correct |
5 ms |
15252 KB |
Output is correct |
37 |
Correct |
5 ms |
15196 KB |
Output is correct |
38 |
Correct |
6 ms |
15360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14684 KB |
Output is correct |
2 |
Correct |
3 ms |
14684 KB |
Output is correct |
3 |
Correct |
4 ms |
14684 KB |
Output is correct |
4 |
Correct |
4 ms |
14684 KB |
Output is correct |
5 |
Correct |
3 ms |
14680 KB |
Output is correct |
6 |
Correct |
3 ms |
14684 KB |
Output is correct |
7 |
Correct |
4 ms |
14916 KB |
Output is correct |
8 |
Correct |
4 ms |
14684 KB |
Output is correct |
9 |
Correct |
3 ms |
14908 KB |
Output is correct |
10 |
Correct |
3 ms |
14684 KB |
Output is correct |
11 |
Correct |
3 ms |
14684 KB |
Output is correct |
12 |
Correct |
3 ms |
14684 KB |
Output is correct |
13 |
Correct |
4 ms |
14680 KB |
Output is correct |
14 |
Correct |
4 ms |
14684 KB |
Output is correct |
15 |
Correct |
4 ms |
14684 KB |
Output is correct |
16 |
Correct |
3 ms |
14684 KB |
Output is correct |
17 |
Correct |
3 ms |
14684 KB |
Output is correct |
18 |
Correct |
3 ms |
14684 KB |
Output is correct |
19 |
Correct |
538 ms |
44032 KB |
Output is correct |
20 |
Correct |
546 ms |
44164 KB |
Output is correct |
21 |
Correct |
549 ms |
42832 KB |
Output is correct |
22 |
Correct |
461 ms |
41556 KB |
Output is correct |
23 |
Correct |
1016 ms |
68996 KB |
Output is correct |
24 |
Correct |
412 ms |
40288 KB |
Output is correct |
25 |
Correct |
719 ms |
41044 KB |
Output is correct |
26 |
Correct |
311 ms |
36180 KB |
Output is correct |
27 |
Correct |
491 ms |
80464 KB |
Output is correct |
28 |
Correct |
2526 ms |
242332 KB |
Output is correct |
29 |
Correct |
2426 ms |
236376 KB |
Output is correct |
30 |
Correct |
489 ms |
80464 KB |
Output is correct |
31 |
Correct |
471 ms |
80428 KB |
Output is correct |
32 |
Correct |
889 ms |
80016 KB |
Output is correct |
33 |
Correct |
1568 ms |
89540 KB |
Output is correct |
34 |
Correct |
2077 ms |
196748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14684 KB |
Output is correct |
2 |
Correct |
3 ms |
14684 KB |
Output is correct |
3 |
Correct |
4 ms |
14684 KB |
Output is correct |
4 |
Correct |
4 ms |
14684 KB |
Output is correct |
5 |
Correct |
3 ms |
14680 KB |
Output is correct |
6 |
Correct |
3 ms |
14684 KB |
Output is correct |
7 |
Correct |
4 ms |
14916 KB |
Output is correct |
8 |
Correct |
4 ms |
14684 KB |
Output is correct |
9 |
Correct |
3 ms |
14908 KB |
Output is correct |
10 |
Correct |
3 ms |
14684 KB |
Output is correct |
11 |
Correct |
3 ms |
14684 KB |
Output is correct |
12 |
Correct |
3 ms |
14684 KB |
Output is correct |
13 |
Correct |
4 ms |
14680 KB |
Output is correct |
14 |
Correct |
4 ms |
14684 KB |
Output is correct |
15 |
Correct |
4 ms |
14684 KB |
Output is correct |
16 |
Correct |
3 ms |
14684 KB |
Output is correct |
17 |
Correct |
3 ms |
14684 KB |
Output is correct |
18 |
Correct |
3 ms |
14684 KB |
Output is correct |
19 |
Correct |
3 ms |
14684 KB |
Output is correct |
20 |
Correct |
3 ms |
14684 KB |
Output is correct |
21 |
Correct |
6 ms |
15196 KB |
Output is correct |
22 |
Correct |
6 ms |
15196 KB |
Output is correct |
23 |
Correct |
6 ms |
15192 KB |
Output is correct |
24 |
Correct |
5 ms |
15196 KB |
Output is correct |
25 |
Correct |
6 ms |
15192 KB |
Output is correct |
26 |
Correct |
5 ms |
15196 KB |
Output is correct |
27 |
Correct |
4 ms |
14936 KB |
Output is correct |
28 |
Correct |
6 ms |
15196 KB |
Output is correct |
29 |
Correct |
6 ms |
15196 KB |
Output is correct |
30 |
Correct |
6 ms |
15196 KB |
Output is correct |
31 |
Correct |
8 ms |
15196 KB |
Output is correct |
32 |
Correct |
6 ms |
15192 KB |
Output is correct |
33 |
Correct |
6 ms |
15196 KB |
Output is correct |
34 |
Correct |
6 ms |
15288 KB |
Output is correct |
35 |
Correct |
6 ms |
15196 KB |
Output is correct |
36 |
Correct |
5 ms |
15252 KB |
Output is correct |
37 |
Correct |
5 ms |
15196 KB |
Output is correct |
38 |
Correct |
6 ms |
15360 KB |
Output is correct |
39 |
Correct |
538 ms |
44032 KB |
Output is correct |
40 |
Correct |
546 ms |
44164 KB |
Output is correct |
41 |
Correct |
549 ms |
42832 KB |
Output is correct |
42 |
Correct |
461 ms |
41556 KB |
Output is correct |
43 |
Correct |
1016 ms |
68996 KB |
Output is correct |
44 |
Correct |
412 ms |
40288 KB |
Output is correct |
45 |
Correct |
719 ms |
41044 KB |
Output is correct |
46 |
Correct |
311 ms |
36180 KB |
Output is correct |
47 |
Correct |
491 ms |
80464 KB |
Output is correct |
48 |
Correct |
2526 ms |
242332 KB |
Output is correct |
49 |
Correct |
2426 ms |
236376 KB |
Output is correct |
50 |
Correct |
489 ms |
80464 KB |
Output is correct |
51 |
Correct |
471 ms |
80428 KB |
Output is correct |
52 |
Correct |
889 ms |
80016 KB |
Output is correct |
53 |
Correct |
1568 ms |
89540 KB |
Output is correct |
54 |
Correct |
2077 ms |
196748 KB |
Output is correct |
55 |
Correct |
41 ms |
19536 KB |
Output is correct |
56 |
Correct |
28 ms |
16976 KB |
Output is correct |
57 |
Correct |
307 ms |
39484 KB |
Output is correct |
58 |
Correct |
85 ms |
26564 KB |
Output is correct |
59 |
Correct |
625 ms |
102216 KB |
Output is correct |
60 |
Correct |
2630 ms |
228984 KB |
Output is correct |
61 |
Correct |
539 ms |
87384 KB |
Output is correct |
62 |
Correct |
479 ms |
80108 KB |
Output is correct |
63 |
Correct |
891 ms |
79952 KB |
Output is correct |
64 |
Correct |
2039 ms |
153628 KB |
Output is correct |
65 |
Correct |
1600 ms |
142700 KB |
Output is correct |
66 |
Correct |
2316 ms |
242408 KB |
Output is correct |
67 |
Correct |
359 ms |
38076 KB |
Output is correct |
68 |
Correct |
921 ms |
93552 KB |
Output is correct |
69 |
Correct |
981 ms |
93308 KB |
Output is correct |
70 |
Correct |
889 ms |
89168 KB |
Output is correct |