# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
386872 |
2021-04-07T14:29:53 Z |
minoum |
Race (IOI11_race) |
C++17 |
|
774 ms |
59268 KB |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAXN = 1e6+10, inf = 1e6+3;
int n, k, mn[MAXN], ans = inf, all, sz[MAXN], par[MAXN], h[MAXN];
vector <pair<int,int>> adj[MAXN];
vector <int> clr;
ll d[MAXN];
bool dead[MAXN];
void dfs(int v, int parv){
all++; sz[v] = 1;
for(auto u: adj[v]){
if(!dead[u.first] && u.first != parv){
par[u.first] = v;
dfs(u.first, v);
sz[v] += sz[u.first];
}
}
return;
}
inline int findcentroid(int v){
all = 0;
int cent = v; par[v] = -1;
dfs(v, -1);
bool f = false;
while(!f){
f = true;
for(auto u: adj[cent]){
if(!dead[u.first] && u.first != par[cent] && sz[u.first] >= (all / 2)){
f = false;
cent = u.first;
break;
}
}
}
return cent;
}
void see(int v, int parv){
if(d[v]<=k) ans = min(ans, h[v]+mn[k-d[v]]);
for(auto i: adj[v]){
int u = i.first, w = i.second;
if(dead[u] || u==parv) continue;
h[u] = h[v]+1; d[u] = d[v]+(ll)w;
see(u, v);
}
return;
}
void add(int v, int parv){
if(d[v]<k){
mn[d[v]] = min(mn[d[v]], h[v]);
clr.push_back(d[v]);
}
for(auto i: adj[v]){
int u = i.first;
if(dead[u] || u == parv) continue;
add(u,v);
}
return;
}
inline void calc(int r){
mn[0] = 0; h[r] = 0; d[r] = 0; clr.push_back(0);
for(auto i: adj[r]){
int u = i.first;
if(dead[u]) continue;
h[u] = 1; d[u] = (ll)i.second;
see(u, r);
add(u, r);
}
while(!clr.empty()){
mn[clr.back()] = inf; clr.pop_back();
}
return;
}
void slv(int v, int tt = 0){
int cent = findcentroid(v);
calc(cent);
dead[cent] = true;
for(auto u: adj[cent])
if(!dead[u.first]) slv(u.first, tt+1);
return;
}
int best_path(int N, int K, int H[][2], int L[]){
n = N; k = K;
for(int i = 0; i < n-1; i++){
adj[H[i][0]].push_back({H[i][1], L[i]});
adj[H[i][1]].push_back({H[i][0], L[i]});
}
for(int i = 0; i < MAXN; i++) mn[i] = inf;
slv(0);
return (ans>=inf?-1:ans);
}
/*int main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> k;
for(int i = 0; i < n-1; i++){
int u,v,w;
cin >> u >> v >> w;
adj[u].push_back({v,w});
adj[v].push_back({u,w});
}
for(int i = 0; i < MAXN; i++) mn[i] = inf;
slv(0);
cout << (ans>=inf?-1:ans) << endl;
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
27756 KB |
Output is correct |
2 |
Correct |
18 ms |
27756 KB |
Output is correct |
3 |
Correct |
18 ms |
27756 KB |
Output is correct |
4 |
Correct |
18 ms |
27756 KB |
Output is correct |
5 |
Correct |
21 ms |
27884 KB |
Output is correct |
6 |
Correct |
18 ms |
27756 KB |
Output is correct |
7 |
Correct |
18 ms |
27756 KB |
Output is correct |
8 |
Correct |
19 ms |
27756 KB |
Output is correct |
9 |
Correct |
18 ms |
27756 KB |
Output is correct |
10 |
Correct |
19 ms |
28012 KB |
Output is correct |
11 |
Correct |
18 ms |
27756 KB |
Output is correct |
12 |
Correct |
18 ms |
27756 KB |
Output is correct |
13 |
Correct |
18 ms |
27756 KB |
Output is correct |
14 |
Correct |
18 ms |
27756 KB |
Output is correct |
15 |
Correct |
19 ms |
27756 KB |
Output is correct |
16 |
Correct |
21 ms |
27756 KB |
Output is correct |
17 |
Correct |
18 ms |
27756 KB |
Output is correct |
18 |
Correct |
22 ms |
27756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
27756 KB |
Output is correct |
2 |
Correct |
18 ms |
27756 KB |
Output is correct |
3 |
Correct |
18 ms |
27756 KB |
Output is correct |
4 |
Correct |
18 ms |
27756 KB |
Output is correct |
5 |
Correct |
21 ms |
27884 KB |
Output is correct |
6 |
Correct |
18 ms |
27756 KB |
Output is correct |
7 |
Correct |
18 ms |
27756 KB |
Output is correct |
8 |
Correct |
19 ms |
27756 KB |
Output is correct |
9 |
Correct |
18 ms |
27756 KB |
Output is correct |
10 |
Correct |
19 ms |
28012 KB |
Output is correct |
11 |
Correct |
18 ms |
27756 KB |
Output is correct |
12 |
Correct |
18 ms |
27756 KB |
Output is correct |
13 |
Correct |
18 ms |
27756 KB |
Output is correct |
14 |
Correct |
18 ms |
27756 KB |
Output is correct |
15 |
Correct |
19 ms |
27756 KB |
Output is correct |
16 |
Correct |
21 ms |
27756 KB |
Output is correct |
17 |
Correct |
18 ms |
27756 KB |
Output is correct |
18 |
Correct |
22 ms |
27756 KB |
Output is correct |
19 |
Correct |
19 ms |
27756 KB |
Output is correct |
20 |
Correct |
18 ms |
27756 KB |
Output is correct |
21 |
Correct |
19 ms |
27884 KB |
Output is correct |
22 |
Correct |
20 ms |
27884 KB |
Output is correct |
23 |
Correct |
19 ms |
27884 KB |
Output is correct |
24 |
Correct |
19 ms |
28012 KB |
Output is correct |
25 |
Correct |
19 ms |
27884 KB |
Output is correct |
26 |
Correct |
21 ms |
27884 KB |
Output is correct |
27 |
Correct |
22 ms |
27884 KB |
Output is correct |
28 |
Correct |
19 ms |
27884 KB |
Output is correct |
29 |
Correct |
20 ms |
27884 KB |
Output is correct |
30 |
Correct |
20 ms |
27884 KB |
Output is correct |
31 |
Correct |
19 ms |
27884 KB |
Output is correct |
32 |
Correct |
21 ms |
27884 KB |
Output is correct |
33 |
Correct |
20 ms |
27884 KB |
Output is correct |
34 |
Correct |
20 ms |
27884 KB |
Output is correct |
35 |
Correct |
19 ms |
27884 KB |
Output is correct |
36 |
Correct |
20 ms |
27884 KB |
Output is correct |
37 |
Correct |
20 ms |
27884 KB |
Output is correct |
38 |
Correct |
19 ms |
27884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
27756 KB |
Output is correct |
2 |
Correct |
18 ms |
27756 KB |
Output is correct |
3 |
Correct |
18 ms |
27756 KB |
Output is correct |
4 |
Correct |
18 ms |
27756 KB |
Output is correct |
5 |
Correct |
21 ms |
27884 KB |
Output is correct |
6 |
Correct |
18 ms |
27756 KB |
Output is correct |
7 |
Correct |
18 ms |
27756 KB |
Output is correct |
8 |
Correct |
19 ms |
27756 KB |
Output is correct |
9 |
Correct |
18 ms |
27756 KB |
Output is correct |
10 |
Correct |
19 ms |
28012 KB |
Output is correct |
11 |
Correct |
18 ms |
27756 KB |
Output is correct |
12 |
Correct |
18 ms |
27756 KB |
Output is correct |
13 |
Correct |
18 ms |
27756 KB |
Output is correct |
14 |
Correct |
18 ms |
27756 KB |
Output is correct |
15 |
Correct |
19 ms |
27756 KB |
Output is correct |
16 |
Correct |
21 ms |
27756 KB |
Output is correct |
17 |
Correct |
18 ms |
27756 KB |
Output is correct |
18 |
Correct |
22 ms |
27756 KB |
Output is correct |
19 |
Correct |
238 ms |
36256 KB |
Output is correct |
20 |
Correct |
245 ms |
36096 KB |
Output is correct |
21 |
Correct |
250 ms |
36460 KB |
Output is correct |
22 |
Correct |
209 ms |
36712 KB |
Output is correct |
23 |
Correct |
195 ms |
36332 KB |
Output is correct |
24 |
Correct |
101 ms |
36332 KB |
Output is correct |
25 |
Correct |
219 ms |
39696 KB |
Output is correct |
26 |
Correct |
131 ms |
43888 KB |
Output is correct |
27 |
Correct |
257 ms |
44908 KB |
Output is correct |
28 |
Correct |
677 ms |
59268 KB |
Output is correct |
29 |
Correct |
619 ms |
58028 KB |
Output is correct |
30 |
Correct |
273 ms |
44840 KB |
Output is correct |
31 |
Correct |
250 ms |
44780 KB |
Output is correct |
32 |
Correct |
372 ms |
44780 KB |
Output is correct |
33 |
Correct |
448 ms |
43628 KB |
Output is correct |
34 |
Correct |
449 ms |
44504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
27756 KB |
Output is correct |
2 |
Correct |
18 ms |
27756 KB |
Output is correct |
3 |
Correct |
18 ms |
27756 KB |
Output is correct |
4 |
Correct |
18 ms |
27756 KB |
Output is correct |
5 |
Correct |
21 ms |
27884 KB |
Output is correct |
6 |
Correct |
18 ms |
27756 KB |
Output is correct |
7 |
Correct |
18 ms |
27756 KB |
Output is correct |
8 |
Correct |
19 ms |
27756 KB |
Output is correct |
9 |
Correct |
18 ms |
27756 KB |
Output is correct |
10 |
Correct |
19 ms |
28012 KB |
Output is correct |
11 |
Correct |
18 ms |
27756 KB |
Output is correct |
12 |
Correct |
18 ms |
27756 KB |
Output is correct |
13 |
Correct |
18 ms |
27756 KB |
Output is correct |
14 |
Correct |
18 ms |
27756 KB |
Output is correct |
15 |
Correct |
19 ms |
27756 KB |
Output is correct |
16 |
Correct |
21 ms |
27756 KB |
Output is correct |
17 |
Correct |
18 ms |
27756 KB |
Output is correct |
18 |
Correct |
22 ms |
27756 KB |
Output is correct |
19 |
Correct |
19 ms |
27756 KB |
Output is correct |
20 |
Correct |
18 ms |
27756 KB |
Output is correct |
21 |
Correct |
19 ms |
27884 KB |
Output is correct |
22 |
Correct |
20 ms |
27884 KB |
Output is correct |
23 |
Correct |
19 ms |
27884 KB |
Output is correct |
24 |
Correct |
19 ms |
28012 KB |
Output is correct |
25 |
Correct |
19 ms |
27884 KB |
Output is correct |
26 |
Correct |
21 ms |
27884 KB |
Output is correct |
27 |
Correct |
22 ms |
27884 KB |
Output is correct |
28 |
Correct |
19 ms |
27884 KB |
Output is correct |
29 |
Correct |
20 ms |
27884 KB |
Output is correct |
30 |
Correct |
20 ms |
27884 KB |
Output is correct |
31 |
Correct |
19 ms |
27884 KB |
Output is correct |
32 |
Correct |
21 ms |
27884 KB |
Output is correct |
33 |
Correct |
20 ms |
27884 KB |
Output is correct |
34 |
Correct |
20 ms |
27884 KB |
Output is correct |
35 |
Correct |
19 ms |
27884 KB |
Output is correct |
36 |
Correct |
20 ms |
27884 KB |
Output is correct |
37 |
Correct |
20 ms |
27884 KB |
Output is correct |
38 |
Correct |
19 ms |
27884 KB |
Output is correct |
39 |
Correct |
238 ms |
36256 KB |
Output is correct |
40 |
Correct |
245 ms |
36096 KB |
Output is correct |
41 |
Correct |
250 ms |
36460 KB |
Output is correct |
42 |
Correct |
209 ms |
36712 KB |
Output is correct |
43 |
Correct |
195 ms |
36332 KB |
Output is correct |
44 |
Correct |
101 ms |
36332 KB |
Output is correct |
45 |
Correct |
219 ms |
39696 KB |
Output is correct |
46 |
Correct |
131 ms |
43888 KB |
Output is correct |
47 |
Correct |
257 ms |
44908 KB |
Output is correct |
48 |
Correct |
677 ms |
59268 KB |
Output is correct |
49 |
Correct |
619 ms |
58028 KB |
Output is correct |
50 |
Correct |
273 ms |
44840 KB |
Output is correct |
51 |
Correct |
250 ms |
44780 KB |
Output is correct |
52 |
Correct |
372 ms |
44780 KB |
Output is correct |
53 |
Correct |
448 ms |
43628 KB |
Output is correct |
54 |
Correct |
449 ms |
44504 KB |
Output is correct |
55 |
Correct |
28 ms |
28652 KB |
Output is correct |
56 |
Correct |
32 ms |
28652 KB |
Output is correct |
57 |
Correct |
105 ms |
36968 KB |
Output is correct |
58 |
Correct |
60 ms |
36832 KB |
Output is correct |
59 |
Correct |
134 ms |
43888 KB |
Output is correct |
60 |
Correct |
725 ms |
59236 KB |
Output is correct |
61 |
Correct |
272 ms |
45304 KB |
Output is correct |
62 |
Correct |
268 ms |
45668 KB |
Output is correct |
63 |
Correct |
384 ms |
45672 KB |
Output is correct |
64 |
Correct |
774 ms |
45944 KB |
Output is correct |
65 |
Correct |
534 ms |
45608 KB |
Output is correct |
66 |
Correct |
754 ms |
55744 KB |
Output is correct |
67 |
Correct |
175 ms |
47284 KB |
Output is correct |
68 |
Correct |
460 ms |
46056 KB |
Output is correct |
69 |
Correct |
416 ms |
46184 KB |
Output is correct |
70 |
Correct |
374 ms |
45160 KB |
Output is correct |