# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
726624 |
2023-04-19T06:52:28 Z |
btkhg |
Race (IOI11_race) |
C++14 |
|
481 ms |
32216 KB |
#include <bits/stdc++.h>
#define fi first
#define se second
#define nmax 200008
#define kmax 1000008
const int inf = 1e9;
using namespace std;
typedef pair<int, int> pii;
int n, k, lim, ans = inf, sz[nmax], f[kmax];
bool kt[nmax];
vector<pii>l[nmax];
int dfs(int x, int pre){
sz[x] = 1;
for (pii it : l[x]){
if (it.fi == pre || kt[it.fi])
continue;
sz[x] += dfs(it.fi, x);
}
return sz[x];
}
int centroid(int rt, int x, int pre){
for (pii it : l[x]){
if (it.fi == pre || kt[it.fi])
continue;
if (sz[it.fi] * 2 > sz[rt])
return centroid(rt, it.fi, x);
}
return x;
}
void calc(int x, int pre, int dis, int d, int flag){
if (dis > k)
return;
switch(flag){
case 0:
ans = min(ans, f[k - dis] + d);
break;
case 1:
f[dis] = min(f[dis], d);
break;
default:
f[dis] = inf;
break;
}
for (pii it : l[x]){
if (it.fi == pre || kt[it.fi])
continue;
calc(it.fi, x, dis + it.se, d + 1, flag);
}
}
void centroid(int x){
dfs(x, x);
x = centroid(x, x, x);
f[0] = 0;
for (pii it : l[x])
if (!kt[it.fi]){
calc(it.fi, x, it.se, 1, 0);
calc(it.fi, x, it.se, 1, 1);
}
for (pii it : l[x])
if (!kt[it.fi])
calc(it.fi, x, it.se, 1, 2);
kt[x] = 1;
f[0] = inf;
for (pii it : l[x])
if (!kt[it.fi])
centroid(it.fi);
}
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 = H[i][0], v = H[i][1], w = L[i];
l[u].push_back({v, w});
l[v].push_back({u, w});
}
memset(kt, false, sizeof(kt));
fill(f, f + k + 1, inf);
centroid(1);
if (ans >= n)
ans = -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
2 |
Correct |
3 ms |
5204 KB |
Output is correct |
3 |
Correct |
3 ms |
5144 KB |
Output is correct |
4 |
Correct |
3 ms |
5152 KB |
Output is correct |
5 |
Correct |
3 ms |
5204 KB |
Output is correct |
6 |
Correct |
3 ms |
5152 KB |
Output is correct |
7 |
Correct |
3 ms |
5144 KB |
Output is correct |
8 |
Correct |
3 ms |
5148 KB |
Output is correct |
9 |
Correct |
3 ms |
5204 KB |
Output is correct |
10 |
Correct |
3 ms |
5204 KB |
Output is correct |
11 |
Correct |
3 ms |
5204 KB |
Output is correct |
12 |
Correct |
3 ms |
5204 KB |
Output is correct |
13 |
Correct |
3 ms |
5204 KB |
Output is correct |
14 |
Correct |
3 ms |
5204 KB |
Output is correct |
15 |
Correct |
3 ms |
5204 KB |
Output is correct |
16 |
Correct |
3 ms |
5204 KB |
Output is correct |
17 |
Correct |
4 ms |
5204 KB |
Output is correct |
18 |
Correct |
3 ms |
5204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
2 |
Correct |
3 ms |
5204 KB |
Output is correct |
3 |
Correct |
3 ms |
5144 KB |
Output is correct |
4 |
Correct |
3 ms |
5152 KB |
Output is correct |
5 |
Correct |
3 ms |
5204 KB |
Output is correct |
6 |
Correct |
3 ms |
5152 KB |
Output is correct |
7 |
Correct |
3 ms |
5144 KB |
Output is correct |
8 |
Correct |
3 ms |
5148 KB |
Output is correct |
9 |
Correct |
3 ms |
5204 KB |
Output is correct |
10 |
Correct |
3 ms |
5204 KB |
Output is correct |
11 |
Correct |
3 ms |
5204 KB |
Output is correct |
12 |
Correct |
3 ms |
5204 KB |
Output is correct |
13 |
Correct |
3 ms |
5204 KB |
Output is correct |
14 |
Correct |
3 ms |
5204 KB |
Output is correct |
15 |
Correct |
3 ms |
5204 KB |
Output is correct |
16 |
Correct |
3 ms |
5204 KB |
Output is correct |
17 |
Correct |
4 ms |
5204 KB |
Output is correct |
18 |
Correct |
3 ms |
5204 KB |
Output is correct |
19 |
Correct |
3 ms |
5144 KB |
Output is correct |
20 |
Correct |
3 ms |
5204 KB |
Output is correct |
21 |
Correct |
4 ms |
5220 KB |
Output is correct |
22 |
Correct |
6 ms |
8868 KB |
Output is correct |
23 |
Correct |
5 ms |
8148 KB |
Output is correct |
24 |
Correct |
5 ms |
8660 KB |
Output is correct |
25 |
Correct |
7 ms |
8524 KB |
Output is correct |
26 |
Correct |
4 ms |
6568 KB |
Output is correct |
27 |
Correct |
5 ms |
8416 KB |
Output is correct |
28 |
Correct |
4 ms |
6044 KB |
Output is correct |
29 |
Correct |
4 ms |
6484 KB |
Output is correct |
30 |
Correct |
5 ms |
6612 KB |
Output is correct |
31 |
Correct |
5 ms |
7768 KB |
Output is correct |
32 |
Correct |
5 ms |
8020 KB |
Output is correct |
33 |
Correct |
6 ms |
8228 KB |
Output is correct |
34 |
Correct |
5 ms |
7508 KB |
Output is correct |
35 |
Correct |
6 ms |
8416 KB |
Output is correct |
36 |
Correct |
5 ms |
8916 KB |
Output is correct |
37 |
Correct |
5 ms |
8404 KB |
Output is correct |
38 |
Correct |
5 ms |
7252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
2 |
Correct |
3 ms |
5204 KB |
Output is correct |
3 |
Correct |
3 ms |
5144 KB |
Output is correct |
4 |
Correct |
3 ms |
5152 KB |
Output is correct |
5 |
Correct |
3 ms |
5204 KB |
Output is correct |
6 |
Correct |
3 ms |
5152 KB |
Output is correct |
7 |
Correct |
3 ms |
5144 KB |
Output is correct |
8 |
Correct |
3 ms |
5148 KB |
Output is correct |
9 |
Correct |
3 ms |
5204 KB |
Output is correct |
10 |
Correct |
3 ms |
5204 KB |
Output is correct |
11 |
Correct |
3 ms |
5204 KB |
Output is correct |
12 |
Correct |
3 ms |
5204 KB |
Output is correct |
13 |
Correct |
3 ms |
5204 KB |
Output is correct |
14 |
Correct |
3 ms |
5204 KB |
Output is correct |
15 |
Correct |
3 ms |
5204 KB |
Output is correct |
16 |
Correct |
3 ms |
5204 KB |
Output is correct |
17 |
Correct |
4 ms |
5204 KB |
Output is correct |
18 |
Correct |
3 ms |
5204 KB |
Output is correct |
19 |
Correct |
115 ms |
11756 KB |
Output is correct |
20 |
Correct |
145 ms |
11784 KB |
Output is correct |
21 |
Correct |
144 ms |
11808 KB |
Output is correct |
22 |
Correct |
128 ms |
11864 KB |
Output is correct |
23 |
Correct |
75 ms |
12108 KB |
Output is correct |
24 |
Correct |
51 ms |
12008 KB |
Output is correct |
25 |
Correct |
116 ms |
16892 KB |
Output is correct |
26 |
Correct |
88 ms |
17456 KB |
Output is correct |
27 |
Correct |
156 ms |
18772 KB |
Output is correct |
28 |
Correct |
217 ms |
29312 KB |
Output is correct |
29 |
Correct |
237 ms |
25036 KB |
Output is correct |
30 |
Correct |
144 ms |
18676 KB |
Output is correct |
31 |
Correct |
149 ms |
18788 KB |
Output is correct |
32 |
Correct |
178 ms |
18884 KB |
Output is correct |
33 |
Correct |
202 ms |
17584 KB |
Output is correct |
34 |
Correct |
162 ms |
18488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
2 |
Correct |
3 ms |
5204 KB |
Output is correct |
3 |
Correct |
3 ms |
5144 KB |
Output is correct |
4 |
Correct |
3 ms |
5152 KB |
Output is correct |
5 |
Correct |
3 ms |
5204 KB |
Output is correct |
6 |
Correct |
3 ms |
5152 KB |
Output is correct |
7 |
Correct |
3 ms |
5144 KB |
Output is correct |
8 |
Correct |
3 ms |
5148 KB |
Output is correct |
9 |
Correct |
3 ms |
5204 KB |
Output is correct |
10 |
Correct |
3 ms |
5204 KB |
Output is correct |
11 |
Correct |
3 ms |
5204 KB |
Output is correct |
12 |
Correct |
3 ms |
5204 KB |
Output is correct |
13 |
Correct |
3 ms |
5204 KB |
Output is correct |
14 |
Correct |
3 ms |
5204 KB |
Output is correct |
15 |
Correct |
3 ms |
5204 KB |
Output is correct |
16 |
Correct |
3 ms |
5204 KB |
Output is correct |
17 |
Correct |
4 ms |
5204 KB |
Output is correct |
18 |
Correct |
3 ms |
5204 KB |
Output is correct |
19 |
Correct |
3 ms |
5144 KB |
Output is correct |
20 |
Correct |
3 ms |
5204 KB |
Output is correct |
21 |
Correct |
4 ms |
5220 KB |
Output is correct |
22 |
Correct |
6 ms |
8868 KB |
Output is correct |
23 |
Correct |
5 ms |
8148 KB |
Output is correct |
24 |
Correct |
5 ms |
8660 KB |
Output is correct |
25 |
Correct |
7 ms |
8524 KB |
Output is correct |
26 |
Correct |
4 ms |
6568 KB |
Output is correct |
27 |
Correct |
5 ms |
8416 KB |
Output is correct |
28 |
Correct |
4 ms |
6044 KB |
Output is correct |
29 |
Correct |
4 ms |
6484 KB |
Output is correct |
30 |
Correct |
5 ms |
6612 KB |
Output is correct |
31 |
Correct |
5 ms |
7768 KB |
Output is correct |
32 |
Correct |
5 ms |
8020 KB |
Output is correct |
33 |
Correct |
6 ms |
8228 KB |
Output is correct |
34 |
Correct |
5 ms |
7508 KB |
Output is correct |
35 |
Correct |
6 ms |
8416 KB |
Output is correct |
36 |
Correct |
5 ms |
8916 KB |
Output is correct |
37 |
Correct |
5 ms |
8404 KB |
Output is correct |
38 |
Correct |
5 ms |
7252 KB |
Output is correct |
39 |
Correct |
115 ms |
11756 KB |
Output is correct |
40 |
Correct |
145 ms |
11784 KB |
Output is correct |
41 |
Correct |
144 ms |
11808 KB |
Output is correct |
42 |
Correct |
128 ms |
11864 KB |
Output is correct |
43 |
Correct |
75 ms |
12108 KB |
Output is correct |
44 |
Correct |
51 ms |
12008 KB |
Output is correct |
45 |
Correct |
116 ms |
16892 KB |
Output is correct |
46 |
Correct |
88 ms |
17456 KB |
Output is correct |
47 |
Correct |
156 ms |
18772 KB |
Output is correct |
48 |
Correct |
217 ms |
29312 KB |
Output is correct |
49 |
Correct |
237 ms |
25036 KB |
Output is correct |
50 |
Correct |
144 ms |
18676 KB |
Output is correct |
51 |
Correct |
149 ms |
18788 KB |
Output is correct |
52 |
Correct |
178 ms |
18884 KB |
Output is correct |
53 |
Correct |
202 ms |
17584 KB |
Output is correct |
54 |
Correct |
162 ms |
18488 KB |
Output is correct |
55 |
Correct |
10 ms |
5844 KB |
Output is correct |
56 |
Correct |
12 ms |
5844 KB |
Output is correct |
57 |
Correct |
81 ms |
12020 KB |
Output is correct |
58 |
Correct |
34 ms |
11712 KB |
Output is correct |
59 |
Correct |
90 ms |
18184 KB |
Output is correct |
60 |
Correct |
442 ms |
29192 KB |
Output is correct |
61 |
Correct |
163 ms |
18908 KB |
Output is correct |
62 |
Correct |
183 ms |
22840 KB |
Output is correct |
63 |
Correct |
267 ms |
22780 KB |
Output is correct |
64 |
Correct |
481 ms |
20848 KB |
Output is correct |
65 |
Correct |
224 ms |
19020 KB |
Output is correct |
66 |
Correct |
422 ms |
32216 KB |
Output is correct |
67 |
Correct |
120 ms |
23236 KB |
Output is correct |
68 |
Correct |
257 ms |
23116 KB |
Output is correct |
69 |
Correct |
258 ms |
23328 KB |
Output is correct |
70 |
Correct |
217 ms |
22664 KB |
Output is correct |