# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
64956 |
2018-08-06T09:19:24 Z |
PeppaPig |
Race (IOI11_race) |
C++14 |
|
1585 ms |
119076 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define x first
#define y second
const int N = 2e5+5;
int n, k;
int dep[N], pos[N], in[N], out[N], sz[N];
long d[N];
vector<pii> g[N];
void get_sz(int u, int p) {
static int idx = 0;
in[u] = ++idx, pos[idx] = u, sz[u] = 1;
if(u) for(auto it = g[u].begin();;++it) if(it->x == p) {
g[u].erase(it); break;
}
for(pii &v : g[u]) {
d[v.x] = d[u] + v.y;
dep[v.x] = dep[u] + 1;
get_sz(v.x, u), sz[u] += sz[v.x];
if(sz[g[u][0].x] < sz[v.x]) swap(v, g[u][0]);
}
out[u] = idx;
}
int ans = 1e9;
map<long, int> M;
void setMap(int u) {
if(M[d[u]] == 0) M[d[u]] = dep[u];
else M[d[u]] = min(M[d[u]], dep[u]);
}
void getVal(int u, int lca) {
long val = k - d[u] + 2*d[lca];
int ret = M[val];
if(ret != 0) {
int z = ret + dep[u] - 2 * dep[lca];
ans = min(ans, z);
}
}
void solve(int u, bool keep) {
for(pii v : g[u]) if(v != g[u][0]) solve(v.x, false);
if(g[u].size()) solve(g[u][0].x, true);
getVal(u, u), setMap(u);
for(pii v : g[u]) if(v != g[u][0]) {
for(int i = in[v.x]; i <= out[v.x]; ++i) getVal(pos[i], u);
for(int i = in[v.x]; i <= out[v.x]; ++i) setMap(pos[i]);
}
if(!keep) M.clear();
}
int best_path(int N, int K, int H[][2], int L[]) {
k= K;
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]);
}
dep[0] = 1;
get_sz(0, -1);
solve(0, false);
return (ans == (int)1e9 ? -1 : ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5080 KB |
Output is correct |
2 |
Correct |
7 ms |
5104 KB |
Output is correct |
3 |
Correct |
7 ms |
5216 KB |
Output is correct |
4 |
Correct |
6 ms |
5220 KB |
Output is correct |
5 |
Correct |
7 ms |
5272 KB |
Output is correct |
6 |
Correct |
6 ms |
5332 KB |
Output is correct |
7 |
Correct |
7 ms |
5332 KB |
Output is correct |
8 |
Correct |
7 ms |
5332 KB |
Output is correct |
9 |
Correct |
7 ms |
5332 KB |
Output is correct |
10 |
Correct |
7 ms |
5332 KB |
Output is correct |
11 |
Correct |
7 ms |
5336 KB |
Output is correct |
12 |
Correct |
8 ms |
5388 KB |
Output is correct |
13 |
Correct |
8 ms |
5496 KB |
Output is correct |
14 |
Correct |
7 ms |
5496 KB |
Output is correct |
15 |
Correct |
9 ms |
5496 KB |
Output is correct |
16 |
Correct |
8 ms |
5496 KB |
Output is correct |
17 |
Correct |
8 ms |
5516 KB |
Output is correct |
18 |
Correct |
15 ms |
5520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5080 KB |
Output is correct |
2 |
Correct |
7 ms |
5104 KB |
Output is correct |
3 |
Correct |
7 ms |
5216 KB |
Output is correct |
4 |
Correct |
6 ms |
5220 KB |
Output is correct |
5 |
Correct |
7 ms |
5272 KB |
Output is correct |
6 |
Correct |
6 ms |
5332 KB |
Output is correct |
7 |
Correct |
7 ms |
5332 KB |
Output is correct |
8 |
Correct |
7 ms |
5332 KB |
Output is correct |
9 |
Correct |
7 ms |
5332 KB |
Output is correct |
10 |
Correct |
7 ms |
5332 KB |
Output is correct |
11 |
Correct |
7 ms |
5336 KB |
Output is correct |
12 |
Correct |
8 ms |
5388 KB |
Output is correct |
13 |
Correct |
8 ms |
5496 KB |
Output is correct |
14 |
Correct |
7 ms |
5496 KB |
Output is correct |
15 |
Correct |
9 ms |
5496 KB |
Output is correct |
16 |
Correct |
8 ms |
5496 KB |
Output is correct |
17 |
Correct |
8 ms |
5516 KB |
Output is correct |
18 |
Correct |
15 ms |
5520 KB |
Output is correct |
19 |
Correct |
8 ms |
5628 KB |
Output is correct |
20 |
Correct |
11 ms |
5752 KB |
Output is correct |
21 |
Correct |
11 ms |
5764 KB |
Output is correct |
22 |
Correct |
9 ms |
5764 KB |
Output is correct |
23 |
Correct |
11 ms |
5764 KB |
Output is correct |
24 |
Correct |
9 ms |
5764 KB |
Output is correct |
25 |
Correct |
9 ms |
5768 KB |
Output is correct |
26 |
Correct |
9 ms |
5784 KB |
Output is correct |
27 |
Correct |
10 ms |
5784 KB |
Output is correct |
28 |
Correct |
10 ms |
5832 KB |
Output is correct |
29 |
Correct |
12 ms |
5848 KB |
Output is correct |
30 |
Correct |
11 ms |
5864 KB |
Output is correct |
31 |
Correct |
14 ms |
5880 KB |
Output is correct |
32 |
Correct |
13 ms |
5896 KB |
Output is correct |
33 |
Correct |
10 ms |
5912 KB |
Output is correct |
34 |
Correct |
10 ms |
5932 KB |
Output is correct |
35 |
Correct |
9 ms |
5944 KB |
Output is correct |
36 |
Correct |
8 ms |
5956 KB |
Output is correct |
37 |
Correct |
9 ms |
5968 KB |
Output is correct |
38 |
Correct |
9 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5080 KB |
Output is correct |
2 |
Correct |
7 ms |
5104 KB |
Output is correct |
3 |
Correct |
7 ms |
5216 KB |
Output is correct |
4 |
Correct |
6 ms |
5220 KB |
Output is correct |
5 |
Correct |
7 ms |
5272 KB |
Output is correct |
6 |
Correct |
6 ms |
5332 KB |
Output is correct |
7 |
Correct |
7 ms |
5332 KB |
Output is correct |
8 |
Correct |
7 ms |
5332 KB |
Output is correct |
9 |
Correct |
7 ms |
5332 KB |
Output is correct |
10 |
Correct |
7 ms |
5332 KB |
Output is correct |
11 |
Correct |
7 ms |
5336 KB |
Output is correct |
12 |
Correct |
8 ms |
5388 KB |
Output is correct |
13 |
Correct |
8 ms |
5496 KB |
Output is correct |
14 |
Correct |
7 ms |
5496 KB |
Output is correct |
15 |
Correct |
9 ms |
5496 KB |
Output is correct |
16 |
Correct |
8 ms |
5496 KB |
Output is correct |
17 |
Correct |
8 ms |
5516 KB |
Output is correct |
18 |
Correct |
15 ms |
5520 KB |
Output is correct |
19 |
Correct |
346 ms |
14916 KB |
Output is correct |
20 |
Correct |
273 ms |
16188 KB |
Output is correct |
21 |
Correct |
263 ms |
17532 KB |
Output is correct |
22 |
Correct |
277 ms |
18888 KB |
Output is correct |
23 |
Correct |
389 ms |
20768 KB |
Output is correct |
24 |
Correct |
304 ms |
21960 KB |
Output is correct |
25 |
Correct |
167 ms |
27380 KB |
Output is correct |
26 |
Correct |
68 ms |
31816 KB |
Output is correct |
27 |
Correct |
334 ms |
35632 KB |
Output is correct |
28 |
Correct |
450 ms |
77544 KB |
Output is correct |
29 |
Correct |
474 ms |
79512 KB |
Output is correct |
30 |
Correct |
408 ms |
79512 KB |
Output is correct |
31 |
Correct |
356 ms |
79512 KB |
Output is correct |
32 |
Correct |
515 ms |
79512 KB |
Output is correct |
33 |
Correct |
656 ms |
79512 KB |
Output is correct |
34 |
Correct |
1240 ms |
80812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5080 KB |
Output is correct |
2 |
Correct |
7 ms |
5104 KB |
Output is correct |
3 |
Correct |
7 ms |
5216 KB |
Output is correct |
4 |
Correct |
6 ms |
5220 KB |
Output is correct |
5 |
Correct |
7 ms |
5272 KB |
Output is correct |
6 |
Correct |
6 ms |
5332 KB |
Output is correct |
7 |
Correct |
7 ms |
5332 KB |
Output is correct |
8 |
Correct |
7 ms |
5332 KB |
Output is correct |
9 |
Correct |
7 ms |
5332 KB |
Output is correct |
10 |
Correct |
7 ms |
5332 KB |
Output is correct |
11 |
Correct |
7 ms |
5336 KB |
Output is correct |
12 |
Correct |
8 ms |
5388 KB |
Output is correct |
13 |
Correct |
8 ms |
5496 KB |
Output is correct |
14 |
Correct |
7 ms |
5496 KB |
Output is correct |
15 |
Correct |
9 ms |
5496 KB |
Output is correct |
16 |
Correct |
8 ms |
5496 KB |
Output is correct |
17 |
Correct |
8 ms |
5516 KB |
Output is correct |
18 |
Correct |
15 ms |
5520 KB |
Output is correct |
19 |
Correct |
8 ms |
5628 KB |
Output is correct |
20 |
Correct |
11 ms |
5752 KB |
Output is correct |
21 |
Correct |
11 ms |
5764 KB |
Output is correct |
22 |
Correct |
9 ms |
5764 KB |
Output is correct |
23 |
Correct |
11 ms |
5764 KB |
Output is correct |
24 |
Correct |
9 ms |
5764 KB |
Output is correct |
25 |
Correct |
9 ms |
5768 KB |
Output is correct |
26 |
Correct |
9 ms |
5784 KB |
Output is correct |
27 |
Correct |
10 ms |
5784 KB |
Output is correct |
28 |
Correct |
10 ms |
5832 KB |
Output is correct |
29 |
Correct |
12 ms |
5848 KB |
Output is correct |
30 |
Correct |
11 ms |
5864 KB |
Output is correct |
31 |
Correct |
14 ms |
5880 KB |
Output is correct |
32 |
Correct |
13 ms |
5896 KB |
Output is correct |
33 |
Correct |
10 ms |
5912 KB |
Output is correct |
34 |
Correct |
10 ms |
5932 KB |
Output is correct |
35 |
Correct |
9 ms |
5944 KB |
Output is correct |
36 |
Correct |
8 ms |
5956 KB |
Output is correct |
37 |
Correct |
9 ms |
5968 KB |
Output is correct |
38 |
Correct |
9 ms |
5980 KB |
Output is correct |
39 |
Correct |
346 ms |
14916 KB |
Output is correct |
40 |
Correct |
273 ms |
16188 KB |
Output is correct |
41 |
Correct |
263 ms |
17532 KB |
Output is correct |
42 |
Correct |
277 ms |
18888 KB |
Output is correct |
43 |
Correct |
389 ms |
20768 KB |
Output is correct |
44 |
Correct |
304 ms |
21960 KB |
Output is correct |
45 |
Correct |
167 ms |
27380 KB |
Output is correct |
46 |
Correct |
68 ms |
31816 KB |
Output is correct |
47 |
Correct |
334 ms |
35632 KB |
Output is correct |
48 |
Correct |
450 ms |
77544 KB |
Output is correct |
49 |
Correct |
474 ms |
79512 KB |
Output is correct |
50 |
Correct |
408 ms |
79512 KB |
Output is correct |
51 |
Correct |
356 ms |
79512 KB |
Output is correct |
52 |
Correct |
515 ms |
79512 KB |
Output is correct |
53 |
Correct |
656 ms |
79512 KB |
Output is correct |
54 |
Correct |
1240 ms |
80812 KB |
Output is correct |
55 |
Correct |
36 ms |
80812 KB |
Output is correct |
56 |
Correct |
22 ms |
80812 KB |
Output is correct |
57 |
Correct |
215 ms |
80812 KB |
Output is correct |
58 |
Correct |
96 ms |
80812 KB |
Output is correct |
59 |
Correct |
206 ms |
80812 KB |
Output is correct |
60 |
Correct |
488 ms |
102060 KB |
Output is correct |
61 |
Correct |
419 ms |
102060 KB |
Output is correct |
62 |
Correct |
347 ms |
102060 KB |
Output is correct |
63 |
Correct |
492 ms |
102060 KB |
Output is correct |
64 |
Correct |
1585 ms |
102060 KB |
Output is correct |
65 |
Correct |
1383 ms |
105092 KB |
Output is correct |
66 |
Correct |
564 ms |
119076 KB |
Output is correct |
67 |
Correct |
373 ms |
119076 KB |
Output is correct |
68 |
Correct |
923 ms |
119076 KB |
Output is correct |
69 |
Correct |
805 ms |
119076 KB |
Output is correct |
70 |
Correct |
678 ms |
119076 KB |
Output is correct |