# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
385832 |
2021-04-05T05:30:33 Z |
negar_a |
Race (IOI11_race) |
C++14 |
|
1016 ms |
35692 KB |
//!yrt tsuj uoy srettam gnihton no emoc
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define S second
const int maxn = 2e5 + 5, maxk = 1e6 + 5;
vector <pii> adj[maxn];
int w[maxn], sz[maxn];
int h[maxn], d[maxn], mn[maxk];
int n, k;
int inf = 1e9 + 7, ans = 1e9 + 7;
bool dead[maxn];
void dfs(int v, int p = -1){
sz[v] = 1;
for(auto u : adj[v]){
if(u.F != p && !dead[u.F]){
d[u.F] = d[v] + w[u.S];
h[u.F] = h[v] + 1;
dfs(u.F, v);
sz[v] += sz[u.F];
}
}
}
int find_centroid(int v, int p, int z){
for(auto u : adj[v]){
if(u.F != p && !dead[u.F] && sz[u.F] > z / 2){
return find_centroid(u.F, v, z);
}
}
return v;
}
void get(int v, int p = -1){
if(k - d[v] >= 0 && k - d[v] < maxk - 2){
ans = min(mn[k - d[v]] + h[v], ans);
}
for(auto u : adj[v]){
if(u.F != p && !dead[u.F]){
get(u.F, v);
}
}
}
void upd(int v, int p = -1){
if(d[v] >= 0 && d[v] < maxk - 2){
mn[d[v]] = min(h[v], mn[d[v]]);
}
for(auto u : adj[v]){
if(u.F != p && !dead[u.F]){
upd(u.F, v);
}
}
}
void clr(int v, int p = -1){
if(d[v] >= 0 && d[v] < maxk - 2){
mn[d[v]] = inf;
}
for(auto u : adj[v]){
if(u.F != p && !dead[u.F]){
clr(u.F, v);
}
}
}
void solve(int v){
dfs(v);
int c = find_centroid(v, -1, sz[v]);
dead[c] = true;
h[c] = d[c] = 0;
dfs(c);
for(auto x : adj[c]){
int u = x.F;
if(!dead[u]){
get(u, c);
upd(u, c);
}
}
ans = min(ans, mn[k]);
clr(c);
for(auto x : adj[c]){
if(!dead[x.F]){
solve(x.F);
}
}
}
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 x = H[i][0], y = H[i][1];
adj[x].push_back({y, i});
adj[y].push_back({x, i});
}
for(int i = 0; i < n - 1; i ++)
w[i] = L[i];
for(int i = 0; i < maxk - 2; i ++){
mn[i] = inf;
}
solve(0);
if(ans >= inf){
ans = -1;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8940 KB |
Output is correct |
2 |
Correct |
7 ms |
8940 KB |
Output is correct |
3 |
Correct |
7 ms |
8940 KB |
Output is correct |
4 |
Correct |
7 ms |
8940 KB |
Output is correct |
5 |
Correct |
7 ms |
8960 KB |
Output is correct |
6 |
Correct |
7 ms |
8940 KB |
Output is correct |
7 |
Correct |
7 ms |
8940 KB |
Output is correct |
8 |
Correct |
7 ms |
8940 KB |
Output is correct |
9 |
Correct |
7 ms |
8940 KB |
Output is correct |
10 |
Correct |
8 ms |
8940 KB |
Output is correct |
11 |
Correct |
7 ms |
8940 KB |
Output is correct |
12 |
Correct |
7 ms |
8940 KB |
Output is correct |
13 |
Correct |
7 ms |
8940 KB |
Output is correct |
14 |
Correct |
7 ms |
8940 KB |
Output is correct |
15 |
Correct |
7 ms |
8940 KB |
Output is correct |
16 |
Correct |
7 ms |
8940 KB |
Output is correct |
17 |
Correct |
7 ms |
8940 KB |
Output is correct |
18 |
Correct |
7 ms |
8940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8940 KB |
Output is correct |
2 |
Correct |
7 ms |
8940 KB |
Output is correct |
3 |
Correct |
7 ms |
8940 KB |
Output is correct |
4 |
Correct |
7 ms |
8940 KB |
Output is correct |
5 |
Correct |
7 ms |
8960 KB |
Output is correct |
6 |
Correct |
7 ms |
8940 KB |
Output is correct |
7 |
Correct |
7 ms |
8940 KB |
Output is correct |
8 |
Correct |
7 ms |
8940 KB |
Output is correct |
9 |
Correct |
7 ms |
8940 KB |
Output is correct |
10 |
Correct |
8 ms |
8940 KB |
Output is correct |
11 |
Correct |
7 ms |
8940 KB |
Output is correct |
12 |
Correct |
7 ms |
8940 KB |
Output is correct |
13 |
Correct |
7 ms |
8940 KB |
Output is correct |
14 |
Correct |
7 ms |
8940 KB |
Output is correct |
15 |
Correct |
7 ms |
8940 KB |
Output is correct |
16 |
Correct |
7 ms |
8940 KB |
Output is correct |
17 |
Correct |
7 ms |
8940 KB |
Output is correct |
18 |
Correct |
7 ms |
8940 KB |
Output is correct |
19 |
Correct |
7 ms |
8940 KB |
Output is correct |
20 |
Correct |
8 ms |
8940 KB |
Output is correct |
21 |
Correct |
8 ms |
9068 KB |
Output is correct |
22 |
Correct |
8 ms |
9068 KB |
Output is correct |
23 |
Correct |
8 ms |
9068 KB |
Output is correct |
24 |
Correct |
8 ms |
9068 KB |
Output is correct |
25 |
Correct |
8 ms |
9068 KB |
Output is correct |
26 |
Correct |
8 ms |
9068 KB |
Output is correct |
27 |
Correct |
8 ms |
9068 KB |
Output is correct |
28 |
Correct |
8 ms |
9068 KB |
Output is correct |
29 |
Correct |
8 ms |
9068 KB |
Output is correct |
30 |
Correct |
8 ms |
9068 KB |
Output is correct |
31 |
Correct |
8 ms |
9068 KB |
Output is correct |
32 |
Correct |
8 ms |
9068 KB |
Output is correct |
33 |
Correct |
8 ms |
9068 KB |
Output is correct |
34 |
Correct |
8 ms |
9068 KB |
Output is correct |
35 |
Correct |
8 ms |
9068 KB |
Output is correct |
36 |
Correct |
9 ms |
9196 KB |
Output is correct |
37 |
Correct |
8 ms |
9068 KB |
Output is correct |
38 |
Correct |
8 ms |
9068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8940 KB |
Output is correct |
2 |
Correct |
7 ms |
8940 KB |
Output is correct |
3 |
Correct |
7 ms |
8940 KB |
Output is correct |
4 |
Correct |
7 ms |
8940 KB |
Output is correct |
5 |
Correct |
7 ms |
8960 KB |
Output is correct |
6 |
Correct |
7 ms |
8940 KB |
Output is correct |
7 |
Correct |
7 ms |
8940 KB |
Output is correct |
8 |
Correct |
7 ms |
8940 KB |
Output is correct |
9 |
Correct |
7 ms |
8940 KB |
Output is correct |
10 |
Correct |
8 ms |
8940 KB |
Output is correct |
11 |
Correct |
7 ms |
8940 KB |
Output is correct |
12 |
Correct |
7 ms |
8940 KB |
Output is correct |
13 |
Correct |
7 ms |
8940 KB |
Output is correct |
14 |
Correct |
7 ms |
8940 KB |
Output is correct |
15 |
Correct |
7 ms |
8940 KB |
Output is correct |
16 |
Correct |
7 ms |
8940 KB |
Output is correct |
17 |
Correct |
7 ms |
8940 KB |
Output is correct |
18 |
Correct |
7 ms |
8940 KB |
Output is correct |
19 |
Correct |
312 ms |
15468 KB |
Output is correct |
20 |
Correct |
304 ms |
15596 KB |
Output is correct |
21 |
Correct |
301 ms |
15468 KB |
Output is correct |
22 |
Correct |
246 ms |
15596 KB |
Output is correct |
23 |
Correct |
214 ms |
15724 KB |
Output is correct |
24 |
Correct |
105 ms |
15724 KB |
Output is correct |
25 |
Correct |
245 ms |
18284 KB |
Output is correct |
26 |
Correct |
135 ms |
21228 KB |
Output is correct |
27 |
Correct |
297 ms |
22124 KB |
Output is correct |
28 |
Correct |
879 ms |
33460 KB |
Output is correct |
29 |
Correct |
922 ms |
32540 KB |
Output is correct |
30 |
Correct |
297 ms |
22252 KB |
Output is correct |
31 |
Correct |
305 ms |
22252 KB |
Output is correct |
32 |
Correct |
478 ms |
22252 KB |
Output is correct |
33 |
Correct |
586 ms |
21100 KB |
Output is correct |
34 |
Correct |
652 ms |
21160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8940 KB |
Output is correct |
2 |
Correct |
7 ms |
8940 KB |
Output is correct |
3 |
Correct |
7 ms |
8940 KB |
Output is correct |
4 |
Correct |
7 ms |
8940 KB |
Output is correct |
5 |
Correct |
7 ms |
8960 KB |
Output is correct |
6 |
Correct |
7 ms |
8940 KB |
Output is correct |
7 |
Correct |
7 ms |
8940 KB |
Output is correct |
8 |
Correct |
7 ms |
8940 KB |
Output is correct |
9 |
Correct |
7 ms |
8940 KB |
Output is correct |
10 |
Correct |
8 ms |
8940 KB |
Output is correct |
11 |
Correct |
7 ms |
8940 KB |
Output is correct |
12 |
Correct |
7 ms |
8940 KB |
Output is correct |
13 |
Correct |
7 ms |
8940 KB |
Output is correct |
14 |
Correct |
7 ms |
8940 KB |
Output is correct |
15 |
Correct |
7 ms |
8940 KB |
Output is correct |
16 |
Correct |
7 ms |
8940 KB |
Output is correct |
17 |
Correct |
7 ms |
8940 KB |
Output is correct |
18 |
Correct |
7 ms |
8940 KB |
Output is correct |
19 |
Correct |
7 ms |
8940 KB |
Output is correct |
20 |
Correct |
8 ms |
8940 KB |
Output is correct |
21 |
Correct |
8 ms |
9068 KB |
Output is correct |
22 |
Correct |
8 ms |
9068 KB |
Output is correct |
23 |
Correct |
8 ms |
9068 KB |
Output is correct |
24 |
Correct |
8 ms |
9068 KB |
Output is correct |
25 |
Correct |
8 ms |
9068 KB |
Output is correct |
26 |
Correct |
8 ms |
9068 KB |
Output is correct |
27 |
Correct |
8 ms |
9068 KB |
Output is correct |
28 |
Correct |
8 ms |
9068 KB |
Output is correct |
29 |
Correct |
8 ms |
9068 KB |
Output is correct |
30 |
Correct |
8 ms |
9068 KB |
Output is correct |
31 |
Correct |
8 ms |
9068 KB |
Output is correct |
32 |
Correct |
8 ms |
9068 KB |
Output is correct |
33 |
Correct |
8 ms |
9068 KB |
Output is correct |
34 |
Correct |
8 ms |
9068 KB |
Output is correct |
35 |
Correct |
8 ms |
9068 KB |
Output is correct |
36 |
Correct |
9 ms |
9196 KB |
Output is correct |
37 |
Correct |
8 ms |
9068 KB |
Output is correct |
38 |
Correct |
8 ms |
9068 KB |
Output is correct |
39 |
Correct |
312 ms |
15468 KB |
Output is correct |
40 |
Correct |
304 ms |
15596 KB |
Output is correct |
41 |
Correct |
301 ms |
15468 KB |
Output is correct |
42 |
Correct |
246 ms |
15596 KB |
Output is correct |
43 |
Correct |
214 ms |
15724 KB |
Output is correct |
44 |
Correct |
105 ms |
15724 KB |
Output is correct |
45 |
Correct |
245 ms |
18284 KB |
Output is correct |
46 |
Correct |
135 ms |
21228 KB |
Output is correct |
47 |
Correct |
297 ms |
22124 KB |
Output is correct |
48 |
Correct |
879 ms |
33460 KB |
Output is correct |
49 |
Correct |
922 ms |
32540 KB |
Output is correct |
50 |
Correct |
297 ms |
22252 KB |
Output is correct |
51 |
Correct |
305 ms |
22252 KB |
Output is correct |
52 |
Correct |
478 ms |
22252 KB |
Output is correct |
53 |
Correct |
586 ms |
21100 KB |
Output is correct |
54 |
Correct |
652 ms |
21160 KB |
Output is correct |
55 |
Correct |
19 ms |
9580 KB |
Output is correct |
56 |
Correct |
20 ms |
9580 KB |
Output is correct |
57 |
Correct |
120 ms |
17024 KB |
Output is correct |
58 |
Correct |
50 ms |
16736 KB |
Output is correct |
59 |
Correct |
134 ms |
22508 KB |
Output is correct |
60 |
Correct |
918 ms |
35692 KB |
Output is correct |
61 |
Correct |
315 ms |
25196 KB |
Output is correct |
62 |
Correct |
294 ms |
25196 KB |
Output is correct |
63 |
Correct |
494 ms |
25196 KB |
Output is correct |
64 |
Correct |
1016 ms |
25408 KB |
Output is correct |
65 |
Correct |
745 ms |
25964 KB |
Output is correct |
66 |
Correct |
891 ms |
33704 KB |
Output is correct |
67 |
Correct |
172 ms |
25948 KB |
Output is correct |
68 |
Correct |
493 ms |
25836 KB |
Output is correct |
69 |
Correct |
510 ms |
26192 KB |
Output is correct |
70 |
Correct |
464 ms |
25380 KB |
Output is correct |