# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
998148 |
2024-06-13T10:38:30 Z |
alexdumitru |
Race (IOI11_race) |
C++14 |
|
112 ms |
27476 KB |
#include "race.h"
#include <iostream>
#include <vector>
using namespace std;
const int NMAX = 1e5;
const int KMAX = 1e6;
vector<pair<int, int>> g[NMAX];
int w[NMAX];
bool used[NMAX];
int minDepth[KMAX + 1];
int Ans;
int get_w(int node, int dad) {
w[node] = 1;
for (auto it : g[node]) {
if (it.first == dad || used[it.first]) continue;
get_w(it.first, node);
w[node] += w[it.first];
}
return w[node];
}
int get_centroid(int node, int dad, int totalW) {
for (auto it : g[node]) {
if (it.first == dad || used[it.first]) continue;
if (w[it.first] > totalW / 2)
return get_centroid(it.first, node, totalW);
}
return node;
}
void dfs_add(int node, int dad, int k, int length, int depth) {
if (length > k) return;
minDepth[length] = min(minDepth[length], depth);
for (auto it : g[node]) {
if (it.first == dad || used[it.first]) continue;
dfs_add(it.first, node, k, length + it.second, depth + 1);
}
}
void dfs_compute(int node, int dad, int k, int length, int depth) {
if (length > k) return;
Ans = min(Ans, depth + minDepth[k - length]);
for (auto it : g[node]) {
if (it.first == dad || used[it.first]) continue;
dfs_compute(it.first, node, k, length + it.second, depth + 1);
}
}
void dfs_clear(int node, int dad, int k, int length) {
if (length > k) return;
minDepth[length] = NMAX;
for (auto it : g[node]) {
if (it.first == dad || used[it.first]) continue;
dfs_clear(it.first, node, k, length + it.second);
}
}
void go(int node, int k) {
int totalW = get_w(node, -1);
int c = get_centroid(node, -1, totalW);
used[c] = true;
minDepth[0] = 0;
for (auto it : g[c]) {
if (used[it.first]) continue;
dfs_compute(it.first, -1, k, it.second, 1);
dfs_add(it.first, -1, k, it.second, 1);
}
dfs_clear(c, -1, k, 0);
for (auto it : g[c])
if (!used[it.first])
go(it.first, k);
}
int best_path(int N, int K, int H[][2], int L[]) {
Ans = N;
for (int i = 0; i <= KMAX; i++) {
minDepth[i] = N + 1;
}
for (int i = 0; i < N - 1; i++) {
g[H[i][0]].emplace_back(H[i][1], L[i]);
g[H[i][1]].emplace_back(H[i][0], L[i]);
}
go(0, K);
return Ans == N ? -1 : Ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
3 ms |
10844 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10844 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
10844 KB |
Output is correct |
10 |
Correct |
2 ms |
10828 KB |
Output is correct |
11 |
Correct |
2 ms |
10844 KB |
Output is correct |
12 |
Correct |
2 ms |
10844 KB |
Output is correct |
13 |
Correct |
4 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10844 KB |
Output is correct |
16 |
Correct |
2 ms |
10844 KB |
Output is correct |
17 |
Correct |
2 ms |
10584 KB |
Output is correct |
18 |
Correct |
2 ms |
10804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
3 ms |
10844 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10844 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
10844 KB |
Output is correct |
10 |
Correct |
2 ms |
10828 KB |
Output is correct |
11 |
Correct |
2 ms |
10844 KB |
Output is correct |
12 |
Correct |
2 ms |
10844 KB |
Output is correct |
13 |
Correct |
4 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10844 KB |
Output is correct |
16 |
Correct |
2 ms |
10844 KB |
Output is correct |
17 |
Correct |
2 ms |
10584 KB |
Output is correct |
18 |
Correct |
2 ms |
10804 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
2 ms |
10844 KB |
Output is correct |
21 |
Correct |
2 ms |
10832 KB |
Output is correct |
22 |
Correct |
2 ms |
10844 KB |
Output is correct |
23 |
Correct |
2 ms |
10844 KB |
Output is correct |
24 |
Correct |
2 ms |
10844 KB |
Output is correct |
25 |
Correct |
3 ms |
10844 KB |
Output is correct |
26 |
Correct |
3 ms |
10844 KB |
Output is correct |
27 |
Correct |
2 ms |
10844 KB |
Output is correct |
28 |
Correct |
2 ms |
10844 KB |
Output is correct |
29 |
Correct |
3 ms |
10840 KB |
Output is correct |
30 |
Correct |
2 ms |
10844 KB |
Output is correct |
31 |
Correct |
3 ms |
10840 KB |
Output is correct |
32 |
Correct |
3 ms |
10844 KB |
Output is correct |
33 |
Correct |
3 ms |
10844 KB |
Output is correct |
34 |
Correct |
2 ms |
10844 KB |
Output is correct |
35 |
Correct |
3 ms |
10840 KB |
Output is correct |
36 |
Correct |
2 ms |
10840 KB |
Output is correct |
37 |
Correct |
3 ms |
10844 KB |
Output is correct |
38 |
Correct |
2 ms |
10844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
3 ms |
10844 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10844 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
10844 KB |
Output is correct |
10 |
Correct |
2 ms |
10828 KB |
Output is correct |
11 |
Correct |
2 ms |
10844 KB |
Output is correct |
12 |
Correct |
2 ms |
10844 KB |
Output is correct |
13 |
Correct |
4 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10844 KB |
Output is correct |
16 |
Correct |
2 ms |
10844 KB |
Output is correct |
17 |
Correct |
2 ms |
10584 KB |
Output is correct |
18 |
Correct |
2 ms |
10804 KB |
Output is correct |
19 |
Correct |
79 ms |
16720 KB |
Output is correct |
20 |
Correct |
79 ms |
17760 KB |
Output is correct |
21 |
Correct |
111 ms |
17452 KB |
Output is correct |
22 |
Correct |
78 ms |
18000 KB |
Output is correct |
23 |
Correct |
80 ms |
18392 KB |
Output is correct |
24 |
Correct |
36 ms |
18156 KB |
Output is correct |
25 |
Correct |
112 ms |
21336 KB |
Output is correct |
26 |
Correct |
72 ms |
24520 KB |
Output is correct |
27 |
Runtime error |
44 ms |
27476 KB |
Execution killed with signal 11 |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
3 ms |
10844 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10844 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
2 ms |
10844 KB |
Output is correct |
10 |
Correct |
2 ms |
10828 KB |
Output is correct |
11 |
Correct |
2 ms |
10844 KB |
Output is correct |
12 |
Correct |
2 ms |
10844 KB |
Output is correct |
13 |
Correct |
4 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10844 KB |
Output is correct |
16 |
Correct |
2 ms |
10844 KB |
Output is correct |
17 |
Correct |
2 ms |
10584 KB |
Output is correct |
18 |
Correct |
2 ms |
10804 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
2 ms |
10844 KB |
Output is correct |
21 |
Correct |
2 ms |
10832 KB |
Output is correct |
22 |
Correct |
2 ms |
10844 KB |
Output is correct |
23 |
Correct |
2 ms |
10844 KB |
Output is correct |
24 |
Correct |
2 ms |
10844 KB |
Output is correct |
25 |
Correct |
3 ms |
10844 KB |
Output is correct |
26 |
Correct |
3 ms |
10844 KB |
Output is correct |
27 |
Correct |
2 ms |
10844 KB |
Output is correct |
28 |
Correct |
2 ms |
10844 KB |
Output is correct |
29 |
Correct |
3 ms |
10840 KB |
Output is correct |
30 |
Correct |
2 ms |
10844 KB |
Output is correct |
31 |
Correct |
3 ms |
10840 KB |
Output is correct |
32 |
Correct |
3 ms |
10844 KB |
Output is correct |
33 |
Correct |
3 ms |
10844 KB |
Output is correct |
34 |
Correct |
2 ms |
10844 KB |
Output is correct |
35 |
Correct |
3 ms |
10840 KB |
Output is correct |
36 |
Correct |
2 ms |
10840 KB |
Output is correct |
37 |
Correct |
3 ms |
10844 KB |
Output is correct |
38 |
Correct |
2 ms |
10844 KB |
Output is correct |
39 |
Correct |
79 ms |
16720 KB |
Output is correct |
40 |
Correct |
79 ms |
17760 KB |
Output is correct |
41 |
Correct |
111 ms |
17452 KB |
Output is correct |
42 |
Correct |
78 ms |
18000 KB |
Output is correct |
43 |
Correct |
80 ms |
18392 KB |
Output is correct |
44 |
Correct |
36 ms |
18156 KB |
Output is correct |
45 |
Correct |
112 ms |
21336 KB |
Output is correct |
46 |
Correct |
72 ms |
24520 KB |
Output is correct |
47 |
Runtime error |
44 ms |
27476 KB |
Execution killed with signal 11 |
48 |
Halted |
0 ms |
0 KB |
- |