# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
98649 |
2019-02-25T02:34:29 Z |
PeppaPig |
Race (IOI11_race) |
C++14 |
|
852 ms |
54248 KB |
#include <race.h>
#include <bits/stdc++.h>
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 2e5 + 5;
int n, k, ans = INT_MAX;
int hv[N], in[N], out[N], pos[N], par[N], dep[N];
long d[N];
map<long, int> mp;
vector<pii> g[N];
int gethv(int u, int p) {
static int idx = 0;
int sz = 1; pii ret(0, -1);
par[u] = p, in[u] = ++idx, pos[idx] = u;
for(pii v : g[u]) if(v.x != p) {
d[v.x] = d[u] + v.y;
dep[v.x] = dep[u] + 1;
int z = gethv(v.x, u);
sz += z, ret = max(ret, pii(z, v.x));
}
out[u] = idx, hv[u] = ret.y;
return sz;
}
void add(int u) {
if(!mp.count(d[u])) mp[d[u]] = dep[u];
else mp[d[u]] = min(mp[d[u]], dep[u]);
}
void getans(int u, int lca) {
long ret = k - d[u] + 2*d[lca];
if(mp.count(ret)) {
int z = mp[ret] + dep[u] - 2*dep[lca];
ans = min(ans, z);
}
}
void dfs(int u, int p, bool keep) {
for(pii v : g[u]) if(v.x != p && v.x != hv[u]) dfs(v.x, u, 0);
if(hv[u] != -1) dfs(hv[u], u, 1);
getans(u, u), add(u);
for(pii v : g[u]) if(v.x != p && v.x != hv[u]) {
for(int i = in[v.x]; i <= out[v.x]; i++) getans(pos[i], u);
for(int i = in[v.x]; i <= out[v.x]; i++) add(pos[i]);
}
if(!keep) mp.clear();
}
int best_path(int N, int K, int H[][2], int L[]) {
n = N, 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]);
}
gethv(0, 0);
dfs(0, 0, 1);
return ans == INT_MAX ? -1 : ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5120 KB |
Output is correct |
2 |
Correct |
6 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5120 KB |
Output is correct |
4 |
Correct |
6 ms |
5120 KB |
Output is correct |
5 |
Correct |
7 ms |
5120 KB |
Output is correct |
6 |
Correct |
6 ms |
5120 KB |
Output is correct |
7 |
Correct |
6 ms |
5120 KB |
Output is correct |
8 |
Correct |
6 ms |
5120 KB |
Output is correct |
9 |
Correct |
6 ms |
5120 KB |
Output is correct |
10 |
Correct |
6 ms |
5120 KB |
Output is correct |
11 |
Correct |
6 ms |
5120 KB |
Output is correct |
12 |
Correct |
7 ms |
5120 KB |
Output is correct |
13 |
Correct |
7 ms |
5096 KB |
Output is correct |
14 |
Correct |
6 ms |
5120 KB |
Output is correct |
15 |
Correct |
6 ms |
5120 KB |
Output is correct |
16 |
Correct |
7 ms |
5120 KB |
Output is correct |
17 |
Correct |
7 ms |
5120 KB |
Output is correct |
18 |
Correct |
6 ms |
5120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5120 KB |
Output is correct |
2 |
Correct |
6 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5120 KB |
Output is correct |
4 |
Correct |
6 ms |
5120 KB |
Output is correct |
5 |
Correct |
7 ms |
5120 KB |
Output is correct |
6 |
Correct |
6 ms |
5120 KB |
Output is correct |
7 |
Correct |
6 ms |
5120 KB |
Output is correct |
8 |
Correct |
6 ms |
5120 KB |
Output is correct |
9 |
Correct |
6 ms |
5120 KB |
Output is correct |
10 |
Correct |
6 ms |
5120 KB |
Output is correct |
11 |
Correct |
6 ms |
5120 KB |
Output is correct |
12 |
Correct |
7 ms |
5120 KB |
Output is correct |
13 |
Correct |
7 ms |
5096 KB |
Output is correct |
14 |
Correct |
6 ms |
5120 KB |
Output is correct |
15 |
Correct |
6 ms |
5120 KB |
Output is correct |
16 |
Correct |
7 ms |
5120 KB |
Output is correct |
17 |
Correct |
7 ms |
5120 KB |
Output is correct |
18 |
Correct |
6 ms |
5120 KB |
Output is correct |
19 |
Correct |
7 ms |
5120 KB |
Output is correct |
20 |
Correct |
6 ms |
5120 KB |
Output is correct |
21 |
Correct |
8 ms |
5120 KB |
Output is correct |
22 |
Correct |
8 ms |
5248 KB |
Output is correct |
23 |
Correct |
9 ms |
5248 KB |
Output is correct |
24 |
Correct |
9 ms |
5220 KB |
Output is correct |
25 |
Correct |
8 ms |
5248 KB |
Output is correct |
26 |
Correct |
10 ms |
5220 KB |
Output is correct |
27 |
Correct |
6 ms |
5120 KB |
Output is correct |
28 |
Correct |
7 ms |
5248 KB |
Output is correct |
29 |
Correct |
9 ms |
5248 KB |
Output is correct |
30 |
Correct |
8 ms |
5248 KB |
Output is correct |
31 |
Correct |
9 ms |
5248 KB |
Output is correct |
32 |
Correct |
10 ms |
5140 KB |
Output is correct |
33 |
Correct |
8 ms |
5248 KB |
Output is correct |
34 |
Correct |
7 ms |
5248 KB |
Output is correct |
35 |
Correct |
7 ms |
5248 KB |
Output is correct |
36 |
Correct |
6 ms |
5248 KB |
Output is correct |
37 |
Correct |
8 ms |
5248 KB |
Output is correct |
38 |
Correct |
7 ms |
5220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5120 KB |
Output is correct |
2 |
Correct |
6 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5120 KB |
Output is correct |
4 |
Correct |
6 ms |
5120 KB |
Output is correct |
5 |
Correct |
7 ms |
5120 KB |
Output is correct |
6 |
Correct |
6 ms |
5120 KB |
Output is correct |
7 |
Correct |
6 ms |
5120 KB |
Output is correct |
8 |
Correct |
6 ms |
5120 KB |
Output is correct |
9 |
Correct |
6 ms |
5120 KB |
Output is correct |
10 |
Correct |
6 ms |
5120 KB |
Output is correct |
11 |
Correct |
6 ms |
5120 KB |
Output is correct |
12 |
Correct |
7 ms |
5120 KB |
Output is correct |
13 |
Correct |
7 ms |
5096 KB |
Output is correct |
14 |
Correct |
6 ms |
5120 KB |
Output is correct |
15 |
Correct |
6 ms |
5120 KB |
Output is correct |
16 |
Correct |
7 ms |
5120 KB |
Output is correct |
17 |
Correct |
7 ms |
5120 KB |
Output is correct |
18 |
Correct |
6 ms |
5120 KB |
Output is correct |
19 |
Correct |
215 ms |
14404 KB |
Output is correct |
20 |
Correct |
248 ms |
14564 KB |
Output is correct |
21 |
Correct |
228 ms |
14328 KB |
Output is correct |
22 |
Correct |
190 ms |
14456 KB |
Output is correct |
23 |
Correct |
257 ms |
14716 KB |
Output is correct |
24 |
Correct |
187 ms |
14584 KB |
Output is correct |
25 |
Correct |
146 ms |
19128 KB |
Output is correct |
26 |
Correct |
80 ms |
23260 KB |
Output is correct |
27 |
Correct |
302 ms |
24312 KB |
Output is correct |
28 |
Correct |
400 ms |
54248 KB |
Output is correct |
29 |
Correct |
433 ms |
52856 KB |
Output is correct |
30 |
Correct |
298 ms |
24332 KB |
Output is correct |
31 |
Correct |
282 ms |
24312 KB |
Output is correct |
32 |
Correct |
420 ms |
24440 KB |
Output is correct |
33 |
Correct |
413 ms |
23192 KB |
Output is correct |
34 |
Correct |
614 ms |
36472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5120 KB |
Output is correct |
2 |
Correct |
6 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5120 KB |
Output is correct |
4 |
Correct |
6 ms |
5120 KB |
Output is correct |
5 |
Correct |
7 ms |
5120 KB |
Output is correct |
6 |
Correct |
6 ms |
5120 KB |
Output is correct |
7 |
Correct |
6 ms |
5120 KB |
Output is correct |
8 |
Correct |
6 ms |
5120 KB |
Output is correct |
9 |
Correct |
6 ms |
5120 KB |
Output is correct |
10 |
Correct |
6 ms |
5120 KB |
Output is correct |
11 |
Correct |
6 ms |
5120 KB |
Output is correct |
12 |
Correct |
7 ms |
5120 KB |
Output is correct |
13 |
Correct |
7 ms |
5096 KB |
Output is correct |
14 |
Correct |
6 ms |
5120 KB |
Output is correct |
15 |
Correct |
6 ms |
5120 KB |
Output is correct |
16 |
Correct |
7 ms |
5120 KB |
Output is correct |
17 |
Correct |
7 ms |
5120 KB |
Output is correct |
18 |
Correct |
6 ms |
5120 KB |
Output is correct |
19 |
Correct |
7 ms |
5120 KB |
Output is correct |
20 |
Correct |
6 ms |
5120 KB |
Output is correct |
21 |
Correct |
8 ms |
5120 KB |
Output is correct |
22 |
Correct |
8 ms |
5248 KB |
Output is correct |
23 |
Correct |
9 ms |
5248 KB |
Output is correct |
24 |
Correct |
9 ms |
5220 KB |
Output is correct |
25 |
Correct |
8 ms |
5248 KB |
Output is correct |
26 |
Correct |
10 ms |
5220 KB |
Output is correct |
27 |
Correct |
6 ms |
5120 KB |
Output is correct |
28 |
Correct |
7 ms |
5248 KB |
Output is correct |
29 |
Correct |
9 ms |
5248 KB |
Output is correct |
30 |
Correct |
8 ms |
5248 KB |
Output is correct |
31 |
Correct |
9 ms |
5248 KB |
Output is correct |
32 |
Correct |
10 ms |
5140 KB |
Output is correct |
33 |
Correct |
8 ms |
5248 KB |
Output is correct |
34 |
Correct |
7 ms |
5248 KB |
Output is correct |
35 |
Correct |
7 ms |
5248 KB |
Output is correct |
36 |
Correct |
6 ms |
5248 KB |
Output is correct |
37 |
Correct |
8 ms |
5248 KB |
Output is correct |
38 |
Correct |
7 ms |
5220 KB |
Output is correct |
39 |
Correct |
215 ms |
14404 KB |
Output is correct |
40 |
Correct |
248 ms |
14564 KB |
Output is correct |
41 |
Correct |
228 ms |
14328 KB |
Output is correct |
42 |
Correct |
190 ms |
14456 KB |
Output is correct |
43 |
Correct |
257 ms |
14716 KB |
Output is correct |
44 |
Correct |
187 ms |
14584 KB |
Output is correct |
45 |
Correct |
146 ms |
19128 KB |
Output is correct |
46 |
Correct |
80 ms |
23260 KB |
Output is correct |
47 |
Correct |
302 ms |
24312 KB |
Output is correct |
48 |
Correct |
400 ms |
54248 KB |
Output is correct |
49 |
Correct |
433 ms |
52856 KB |
Output is correct |
50 |
Correct |
298 ms |
24332 KB |
Output is correct |
51 |
Correct |
282 ms |
24312 KB |
Output is correct |
52 |
Correct |
420 ms |
24440 KB |
Output is correct |
53 |
Correct |
413 ms |
23192 KB |
Output is correct |
54 |
Correct |
614 ms |
36472 KB |
Output is correct |
55 |
Correct |
28 ms |
6344 KB |
Output is correct |
56 |
Correct |
14 ms |
6016 KB |
Output is correct |
57 |
Correct |
109 ms |
14664 KB |
Output is correct |
58 |
Correct |
61 ms |
14448 KB |
Output is correct |
59 |
Correct |
111 ms |
29532 KB |
Output is correct |
60 |
Correct |
394 ms |
53168 KB |
Output is correct |
61 |
Correct |
385 ms |
26184 KB |
Output is correct |
62 |
Correct |
273 ms |
24440 KB |
Output is correct |
63 |
Correct |
450 ms |
24532 KB |
Output is correct |
64 |
Correct |
778 ms |
30840 KB |
Output is correct |
65 |
Correct |
852 ms |
37584 KB |
Output is correct |
66 |
Correct |
422 ms |
49784 KB |
Output is correct |
67 |
Correct |
447 ms |
25092 KB |
Output is correct |
68 |
Correct |
592 ms |
35580 KB |
Output is correct |
69 |
Correct |
590 ms |
35832 KB |
Output is correct |
70 |
Correct |
578 ms |
34380 KB |
Output is correct |