# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
104113 |
2019-04-04T05:43:41 Z |
rkocharyan |
Race (IOI11_race) |
C++14 |
|
3000 ms |
45944 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
const int K = 1e6 + 7;
const int LG = 20;
const int inf = 1e9 + 7;
int n, k;
int sz[N];
bool used[N];
vector <pair <int, int> > g[N];
vector <int> kek(K, inf);
vector <int> go;
int ans = inf;
void calc(int v, int pr) {
sz[v] = 1;
for (auto to : g[v]) {
if (to.first != pr && !used[to.first]) {
calc(to.first, v);
sz[v] += sz[to.first];
}
}
}
int centroid(int v, int pr, int need) {
for (auto to : g[v]) {
if (to.first != pr && !used[to.first] && sz[to.first] > need / 2) {
return centroid(to.first, v, need);
}
}
return v;
}
void dfs(int v, int pr, int h, int cur) {
if (cur > k) {
return;
}
go.push_back(cur);
kek[cur] = min(kek[cur], h);
for (auto to : g[v]) {
if (to.first != pr && !used[to.first]) {
dfs(to.first, v, h + 1, cur + to.second);
}
}
}
void build(int v, int lg) {
calc(v, -1);
v = centroid(v, -1, sz[v]);
vector <int> dp(k + 1, inf);
dp[0] = 0;
kek[0] = 0;
for (auto to : g[v]) {
if (!used[to.first]) {
dfs(to.first, v, 1, to.second);
go.push_back(0);
for (int x : go) {
ans = min(ans, kek[x] + dp[k - x]);
}
for (int x : go) {
dp[x] = min(dp[x], kek[x]);
kek[x] = inf;
}
go = {};
}
}
used[v] = true;
for (auto to : g[v]) {
if (!used[to.first]) {
build(to.first, lg + 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++) {
int u, v, l;
u = H[i][0];
v = H[i][1];
l = L[i];
g[u].push_back({v, l});
g[v].push_back({u, l});
}
build(0, 0);
return (ans == inf ? -1 : ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
8960 KB |
Output is correct |
2 |
Correct |
10 ms |
8932 KB |
Output is correct |
3 |
Correct |
12 ms |
9060 KB |
Output is correct |
4 |
Correct |
12 ms |
8960 KB |
Output is correct |
5 |
Correct |
12 ms |
8960 KB |
Output is correct |
6 |
Correct |
13 ms |
8960 KB |
Output is correct |
7 |
Correct |
13 ms |
8960 KB |
Output is correct |
8 |
Correct |
10 ms |
8960 KB |
Output is correct |
9 |
Correct |
10 ms |
8960 KB |
Output is correct |
10 |
Correct |
12 ms |
8960 KB |
Output is correct |
11 |
Correct |
10 ms |
8960 KB |
Output is correct |
12 |
Correct |
9 ms |
8960 KB |
Output is correct |
13 |
Correct |
10 ms |
8960 KB |
Output is correct |
14 |
Correct |
11 ms |
8960 KB |
Output is correct |
15 |
Correct |
12 ms |
8960 KB |
Output is correct |
16 |
Correct |
11 ms |
8960 KB |
Output is correct |
17 |
Correct |
10 ms |
8960 KB |
Output is correct |
18 |
Correct |
12 ms |
8960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
8960 KB |
Output is correct |
2 |
Correct |
10 ms |
8932 KB |
Output is correct |
3 |
Correct |
12 ms |
9060 KB |
Output is correct |
4 |
Correct |
12 ms |
8960 KB |
Output is correct |
5 |
Correct |
12 ms |
8960 KB |
Output is correct |
6 |
Correct |
13 ms |
8960 KB |
Output is correct |
7 |
Correct |
13 ms |
8960 KB |
Output is correct |
8 |
Correct |
10 ms |
8960 KB |
Output is correct |
9 |
Correct |
10 ms |
8960 KB |
Output is correct |
10 |
Correct |
12 ms |
8960 KB |
Output is correct |
11 |
Correct |
10 ms |
8960 KB |
Output is correct |
12 |
Correct |
9 ms |
8960 KB |
Output is correct |
13 |
Correct |
10 ms |
8960 KB |
Output is correct |
14 |
Correct |
11 ms |
8960 KB |
Output is correct |
15 |
Correct |
12 ms |
8960 KB |
Output is correct |
16 |
Correct |
11 ms |
8960 KB |
Output is correct |
17 |
Correct |
10 ms |
8960 KB |
Output is correct |
18 |
Correct |
12 ms |
8960 KB |
Output is correct |
19 |
Correct |
11 ms |
8960 KB |
Output is correct |
20 |
Correct |
10 ms |
8960 KB |
Output is correct |
21 |
Correct |
11 ms |
9096 KB |
Output is correct |
22 |
Correct |
2131 ms |
45336 KB |
Output is correct |
23 |
Correct |
1696 ms |
38724 KB |
Output is correct |
24 |
Correct |
2166 ms |
36416 KB |
Output is correct |
25 |
Correct |
1848 ms |
38860 KB |
Output is correct |
26 |
Correct |
649 ms |
19860 KB |
Output is correct |
27 |
Correct |
1945 ms |
37400 KB |
Output is correct |
28 |
Correct |
381 ms |
16256 KB |
Output is correct |
29 |
Correct |
706 ms |
20664 KB |
Output is correct |
30 |
Correct |
989 ms |
22228 KB |
Output is correct |
31 |
Correct |
1681 ms |
32340 KB |
Output is correct |
32 |
Correct |
1793 ms |
37124 KB |
Output is correct |
33 |
Correct |
1766 ms |
39924 KB |
Output is correct |
34 |
Correct |
1436 ms |
32420 KB |
Output is correct |
35 |
Correct |
2058 ms |
41212 KB |
Output is correct |
36 |
Correct |
2163 ms |
45944 KB |
Output is correct |
37 |
Correct |
1764 ms |
40436 KB |
Output is correct |
38 |
Correct |
1198 ms |
29168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
8960 KB |
Output is correct |
2 |
Correct |
10 ms |
8932 KB |
Output is correct |
3 |
Correct |
12 ms |
9060 KB |
Output is correct |
4 |
Correct |
12 ms |
8960 KB |
Output is correct |
5 |
Correct |
12 ms |
8960 KB |
Output is correct |
6 |
Correct |
13 ms |
8960 KB |
Output is correct |
7 |
Correct |
13 ms |
8960 KB |
Output is correct |
8 |
Correct |
10 ms |
8960 KB |
Output is correct |
9 |
Correct |
10 ms |
8960 KB |
Output is correct |
10 |
Correct |
12 ms |
8960 KB |
Output is correct |
11 |
Correct |
10 ms |
8960 KB |
Output is correct |
12 |
Correct |
9 ms |
8960 KB |
Output is correct |
13 |
Correct |
10 ms |
8960 KB |
Output is correct |
14 |
Correct |
11 ms |
8960 KB |
Output is correct |
15 |
Correct |
12 ms |
8960 KB |
Output is correct |
16 |
Correct |
11 ms |
8960 KB |
Output is correct |
17 |
Correct |
10 ms |
8960 KB |
Output is correct |
18 |
Correct |
12 ms |
8960 KB |
Output is correct |
19 |
Correct |
201 ms |
14320 KB |
Output is correct |
20 |
Correct |
193 ms |
14328 KB |
Output is correct |
21 |
Correct |
237 ms |
14656 KB |
Output is correct |
22 |
Correct |
200 ms |
14712 KB |
Output is correct |
23 |
Correct |
161 ms |
14584 KB |
Output is correct |
24 |
Correct |
112 ms |
14688 KB |
Output is correct |
25 |
Correct |
286 ms |
17100 KB |
Output is correct |
26 |
Correct |
123 ms |
20344 KB |
Output is correct |
27 |
Correct |
251 ms |
19784 KB |
Output is correct |
28 |
Correct |
484 ms |
31208 KB |
Output is correct |
29 |
Correct |
506 ms |
30076 KB |
Output is correct |
30 |
Correct |
365 ms |
19864 KB |
Output is correct |
31 |
Correct |
313 ms |
19972 KB |
Output is correct |
32 |
Correct |
321 ms |
19908 KB |
Output is correct |
33 |
Correct |
445 ms |
18808 KB |
Output is correct |
34 |
Correct |
396 ms |
18608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
8960 KB |
Output is correct |
2 |
Correct |
10 ms |
8932 KB |
Output is correct |
3 |
Correct |
12 ms |
9060 KB |
Output is correct |
4 |
Correct |
12 ms |
8960 KB |
Output is correct |
5 |
Correct |
12 ms |
8960 KB |
Output is correct |
6 |
Correct |
13 ms |
8960 KB |
Output is correct |
7 |
Correct |
13 ms |
8960 KB |
Output is correct |
8 |
Correct |
10 ms |
8960 KB |
Output is correct |
9 |
Correct |
10 ms |
8960 KB |
Output is correct |
10 |
Correct |
12 ms |
8960 KB |
Output is correct |
11 |
Correct |
10 ms |
8960 KB |
Output is correct |
12 |
Correct |
9 ms |
8960 KB |
Output is correct |
13 |
Correct |
10 ms |
8960 KB |
Output is correct |
14 |
Correct |
11 ms |
8960 KB |
Output is correct |
15 |
Correct |
12 ms |
8960 KB |
Output is correct |
16 |
Correct |
11 ms |
8960 KB |
Output is correct |
17 |
Correct |
10 ms |
8960 KB |
Output is correct |
18 |
Correct |
12 ms |
8960 KB |
Output is correct |
19 |
Correct |
11 ms |
8960 KB |
Output is correct |
20 |
Correct |
10 ms |
8960 KB |
Output is correct |
21 |
Correct |
11 ms |
9096 KB |
Output is correct |
22 |
Correct |
2131 ms |
45336 KB |
Output is correct |
23 |
Correct |
1696 ms |
38724 KB |
Output is correct |
24 |
Correct |
2166 ms |
36416 KB |
Output is correct |
25 |
Correct |
1848 ms |
38860 KB |
Output is correct |
26 |
Correct |
649 ms |
19860 KB |
Output is correct |
27 |
Correct |
1945 ms |
37400 KB |
Output is correct |
28 |
Correct |
381 ms |
16256 KB |
Output is correct |
29 |
Correct |
706 ms |
20664 KB |
Output is correct |
30 |
Correct |
989 ms |
22228 KB |
Output is correct |
31 |
Correct |
1681 ms |
32340 KB |
Output is correct |
32 |
Correct |
1793 ms |
37124 KB |
Output is correct |
33 |
Correct |
1766 ms |
39924 KB |
Output is correct |
34 |
Correct |
1436 ms |
32420 KB |
Output is correct |
35 |
Correct |
2058 ms |
41212 KB |
Output is correct |
36 |
Correct |
2163 ms |
45944 KB |
Output is correct |
37 |
Correct |
1764 ms |
40436 KB |
Output is correct |
38 |
Correct |
1198 ms |
29168 KB |
Output is correct |
39 |
Correct |
201 ms |
14320 KB |
Output is correct |
40 |
Correct |
193 ms |
14328 KB |
Output is correct |
41 |
Correct |
237 ms |
14656 KB |
Output is correct |
42 |
Correct |
200 ms |
14712 KB |
Output is correct |
43 |
Correct |
161 ms |
14584 KB |
Output is correct |
44 |
Correct |
112 ms |
14688 KB |
Output is correct |
45 |
Correct |
286 ms |
17100 KB |
Output is correct |
46 |
Correct |
123 ms |
20344 KB |
Output is correct |
47 |
Correct |
251 ms |
19784 KB |
Output is correct |
48 |
Correct |
484 ms |
31208 KB |
Output is correct |
49 |
Correct |
506 ms |
30076 KB |
Output is correct |
50 |
Correct |
365 ms |
19864 KB |
Output is correct |
51 |
Correct |
313 ms |
19972 KB |
Output is correct |
52 |
Correct |
321 ms |
19908 KB |
Output is correct |
53 |
Correct |
445 ms |
18808 KB |
Output is correct |
54 |
Correct |
396 ms |
18608 KB |
Output is correct |
55 |
Correct |
48 ms |
9816 KB |
Output is correct |
56 |
Correct |
23 ms |
9600 KB |
Output is correct |
57 |
Correct |
99 ms |
14840 KB |
Output is correct |
58 |
Correct |
71 ms |
14540 KB |
Output is correct |
59 |
Execution timed out |
3039 ms |
33096 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |