# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1037475 |
2024-07-28T23:49:26 Z |
ArthuroWich |
Race (IOI11_race) |
C++17 |
|
254 ms |
262144 KB |
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
int n, k, ans = INT_MAX, proc[200005], si[200005];
vector<pair<int, int>> adj[200005];
map<int, int> occ[22][200005];
void dfs(int i, int p) {
si[i] = 1;
for (auto [j, _] : adj[i]) {
if (proc[j] || j == p) {
continue;
}
dfs(j, i);
si[i] += si[j];
}
}
int centroid(int i, int p, int s) {
for (auto [j, w] : adj[i]) {
if (proc[j] || j == p) {
continue;
}
if (si[j] > s/2) {
return centroid(j, i, s);
}
}
return i;
}
void calc(int i, int p, int d, int path, int l, int h, int c) {
if (path > k) {
return;
}
if (occ[l][h].find(path) == occ[l][h].end()) {
occ[l][h][path] = d;
} else {
occ[l][h][path] = min(occ[l][h][path], d);
}
if (k == path) {
ans = min(ans, d);
} else if (occ[l][c].find(k-path) != occ[l][c].end()) {
ans = min(ans, d+occ[l][c][k-path]);
}
for (auto [j, w] : adj[i]) {
if (proc[j] || j == p) {
continue;
}
calc(j, i, d+1, path+w, l, h, c);
}
}
void decompose(int i, int l) {
dfs(i, -1);
if (si[i] == 1 || proc[i]) {
return;
}
i = centroid(i, -1, si[i]);
proc[i] = 1;
for (auto [j, w] : adj[i]) {
if (proc[j]) {
continue;
}
calc(j, i, 1, w, l, j, i);
if (occ[l][i].size() < occ[l][j].size()) {
occ[l][i].swap(occ[l][j]);
}
for (auto c : occ[l][j]) {
if (occ[l][i].find(c.first) != occ[l][i].end()) {
occ[l][i][c.first] = min(occ[l][i][c.first], c.second);
} else {
occ[l][i][c.first] = c.second;
}
}
}
for (auto [j, w] : adj[i]) {
if (proc[j]) {
continue;
}
decompose(j, l+1);
}
}
int best_path(int N, int K, int H[][2], int L[]) {
n = N;
k = K;
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]});
}
decompose(0, 0);
if (ans == INT_MAX) {
return -1;
} else {
return ans;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
215892 KB |
Output is correct |
2 |
Correct |
33 ms |
215680 KB |
Output is correct |
3 |
Correct |
33 ms |
215900 KB |
Output is correct |
4 |
Correct |
33 ms |
215776 KB |
Output is correct |
5 |
Correct |
33 ms |
215892 KB |
Output is correct |
6 |
Correct |
33 ms |
215896 KB |
Output is correct |
7 |
Correct |
33 ms |
215888 KB |
Output is correct |
8 |
Correct |
32 ms |
215896 KB |
Output is correct |
9 |
Correct |
34 ms |
215900 KB |
Output is correct |
10 |
Correct |
34 ms |
215756 KB |
Output is correct |
11 |
Correct |
34 ms |
215900 KB |
Output is correct |
12 |
Correct |
34 ms |
215900 KB |
Output is correct |
13 |
Correct |
33 ms |
215892 KB |
Output is correct |
14 |
Correct |
33 ms |
215712 KB |
Output is correct |
15 |
Correct |
35 ms |
215888 KB |
Output is correct |
16 |
Correct |
35 ms |
215892 KB |
Output is correct |
17 |
Correct |
36 ms |
215892 KB |
Output is correct |
18 |
Correct |
31 ms |
215900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
215892 KB |
Output is correct |
2 |
Correct |
33 ms |
215680 KB |
Output is correct |
3 |
Correct |
33 ms |
215900 KB |
Output is correct |
4 |
Correct |
33 ms |
215776 KB |
Output is correct |
5 |
Correct |
33 ms |
215892 KB |
Output is correct |
6 |
Correct |
33 ms |
215896 KB |
Output is correct |
7 |
Correct |
33 ms |
215888 KB |
Output is correct |
8 |
Correct |
32 ms |
215896 KB |
Output is correct |
9 |
Correct |
34 ms |
215900 KB |
Output is correct |
10 |
Correct |
34 ms |
215756 KB |
Output is correct |
11 |
Correct |
34 ms |
215900 KB |
Output is correct |
12 |
Correct |
34 ms |
215900 KB |
Output is correct |
13 |
Correct |
33 ms |
215892 KB |
Output is correct |
14 |
Correct |
33 ms |
215712 KB |
Output is correct |
15 |
Correct |
35 ms |
215888 KB |
Output is correct |
16 |
Correct |
35 ms |
215892 KB |
Output is correct |
17 |
Correct |
36 ms |
215892 KB |
Output is correct |
18 |
Correct |
31 ms |
215900 KB |
Output is correct |
19 |
Correct |
34 ms |
215900 KB |
Output is correct |
20 |
Correct |
35 ms |
215896 KB |
Output is correct |
21 |
Correct |
37 ms |
216148 KB |
Output is correct |
22 |
Correct |
34 ms |
215952 KB |
Output is correct |
23 |
Correct |
34 ms |
215896 KB |
Output is correct |
24 |
Correct |
34 ms |
215896 KB |
Output is correct |
25 |
Correct |
34 ms |
216156 KB |
Output is correct |
26 |
Correct |
33 ms |
215900 KB |
Output is correct |
27 |
Correct |
34 ms |
215900 KB |
Output is correct |
28 |
Correct |
36 ms |
216156 KB |
Output is correct |
29 |
Correct |
34 ms |
216152 KB |
Output is correct |
30 |
Correct |
35 ms |
216144 KB |
Output is correct |
31 |
Correct |
34 ms |
216156 KB |
Output is correct |
32 |
Correct |
35 ms |
216060 KB |
Output is correct |
33 |
Correct |
38 ms |
216152 KB |
Output is correct |
34 |
Correct |
33 ms |
216144 KB |
Output is correct |
35 |
Correct |
34 ms |
216152 KB |
Output is correct |
36 |
Correct |
35 ms |
216152 KB |
Output is correct |
37 |
Correct |
33 ms |
216156 KB |
Output is correct |
38 |
Correct |
34 ms |
216144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
215892 KB |
Output is correct |
2 |
Correct |
33 ms |
215680 KB |
Output is correct |
3 |
Correct |
33 ms |
215900 KB |
Output is correct |
4 |
Correct |
33 ms |
215776 KB |
Output is correct |
5 |
Correct |
33 ms |
215892 KB |
Output is correct |
6 |
Correct |
33 ms |
215896 KB |
Output is correct |
7 |
Correct |
33 ms |
215888 KB |
Output is correct |
8 |
Correct |
32 ms |
215896 KB |
Output is correct |
9 |
Correct |
34 ms |
215900 KB |
Output is correct |
10 |
Correct |
34 ms |
215756 KB |
Output is correct |
11 |
Correct |
34 ms |
215900 KB |
Output is correct |
12 |
Correct |
34 ms |
215900 KB |
Output is correct |
13 |
Correct |
33 ms |
215892 KB |
Output is correct |
14 |
Correct |
33 ms |
215712 KB |
Output is correct |
15 |
Correct |
35 ms |
215888 KB |
Output is correct |
16 |
Correct |
35 ms |
215892 KB |
Output is correct |
17 |
Correct |
36 ms |
215892 KB |
Output is correct |
18 |
Correct |
31 ms |
215900 KB |
Output is correct |
19 |
Correct |
201 ms |
245076 KB |
Output is correct |
20 |
Correct |
199 ms |
245280 KB |
Output is correct |
21 |
Correct |
201 ms |
244304 KB |
Output is correct |
22 |
Correct |
195 ms |
243024 KB |
Output is correct |
23 |
Correct |
111 ms |
233292 KB |
Output is correct |
24 |
Correct |
113 ms |
235312 KB |
Output is correct |
25 |
Correct |
151 ms |
235160 KB |
Output is correct |
26 |
Correct |
102 ms |
234120 KB |
Output is correct |
27 |
Correct |
222 ms |
257104 KB |
Output is correct |
28 |
Correct |
254 ms |
257928 KB |
Output is correct |
29 |
Correct |
233 ms |
256140 KB |
Output is correct |
30 |
Correct |
211 ms |
257280 KB |
Output is correct |
31 |
Correct |
211 ms |
257276 KB |
Output is correct |
32 |
Correct |
226 ms |
252176 KB |
Output is correct |
33 |
Runtime error |
200 ms |
262144 KB |
Execution killed with signal 9 |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
215892 KB |
Output is correct |
2 |
Correct |
33 ms |
215680 KB |
Output is correct |
3 |
Correct |
33 ms |
215900 KB |
Output is correct |
4 |
Correct |
33 ms |
215776 KB |
Output is correct |
5 |
Correct |
33 ms |
215892 KB |
Output is correct |
6 |
Correct |
33 ms |
215896 KB |
Output is correct |
7 |
Correct |
33 ms |
215888 KB |
Output is correct |
8 |
Correct |
32 ms |
215896 KB |
Output is correct |
9 |
Correct |
34 ms |
215900 KB |
Output is correct |
10 |
Correct |
34 ms |
215756 KB |
Output is correct |
11 |
Correct |
34 ms |
215900 KB |
Output is correct |
12 |
Correct |
34 ms |
215900 KB |
Output is correct |
13 |
Correct |
33 ms |
215892 KB |
Output is correct |
14 |
Correct |
33 ms |
215712 KB |
Output is correct |
15 |
Correct |
35 ms |
215888 KB |
Output is correct |
16 |
Correct |
35 ms |
215892 KB |
Output is correct |
17 |
Correct |
36 ms |
215892 KB |
Output is correct |
18 |
Correct |
31 ms |
215900 KB |
Output is correct |
19 |
Correct |
34 ms |
215900 KB |
Output is correct |
20 |
Correct |
35 ms |
215896 KB |
Output is correct |
21 |
Correct |
37 ms |
216148 KB |
Output is correct |
22 |
Correct |
34 ms |
215952 KB |
Output is correct |
23 |
Correct |
34 ms |
215896 KB |
Output is correct |
24 |
Correct |
34 ms |
215896 KB |
Output is correct |
25 |
Correct |
34 ms |
216156 KB |
Output is correct |
26 |
Correct |
33 ms |
215900 KB |
Output is correct |
27 |
Correct |
34 ms |
215900 KB |
Output is correct |
28 |
Correct |
36 ms |
216156 KB |
Output is correct |
29 |
Correct |
34 ms |
216152 KB |
Output is correct |
30 |
Correct |
35 ms |
216144 KB |
Output is correct |
31 |
Correct |
34 ms |
216156 KB |
Output is correct |
32 |
Correct |
35 ms |
216060 KB |
Output is correct |
33 |
Correct |
38 ms |
216152 KB |
Output is correct |
34 |
Correct |
33 ms |
216144 KB |
Output is correct |
35 |
Correct |
34 ms |
216152 KB |
Output is correct |
36 |
Correct |
35 ms |
216152 KB |
Output is correct |
37 |
Correct |
33 ms |
216156 KB |
Output is correct |
38 |
Correct |
34 ms |
216144 KB |
Output is correct |
39 |
Correct |
201 ms |
245076 KB |
Output is correct |
40 |
Correct |
199 ms |
245280 KB |
Output is correct |
41 |
Correct |
201 ms |
244304 KB |
Output is correct |
42 |
Correct |
195 ms |
243024 KB |
Output is correct |
43 |
Correct |
111 ms |
233292 KB |
Output is correct |
44 |
Correct |
113 ms |
235312 KB |
Output is correct |
45 |
Correct |
151 ms |
235160 KB |
Output is correct |
46 |
Correct |
102 ms |
234120 KB |
Output is correct |
47 |
Correct |
222 ms |
257104 KB |
Output is correct |
48 |
Correct |
254 ms |
257928 KB |
Output is correct |
49 |
Correct |
233 ms |
256140 KB |
Output is correct |
50 |
Correct |
211 ms |
257280 KB |
Output is correct |
51 |
Correct |
211 ms |
257276 KB |
Output is correct |
52 |
Correct |
226 ms |
252176 KB |
Output is correct |
53 |
Runtime error |
200 ms |
262144 KB |
Execution killed with signal 9 |
54 |
Halted |
0 ms |
0 KB |
- |