# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
556224 |
2022-05-02T15:30:31 Z |
Dan4Life |
Race (IOI11_race) |
C++17 |
|
672 ms |
56868 KB |
#include "race.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int answ, KK, cnt[1000010], subtree[maxn], timer=-1, a[1000010];
set<pair<int,int>> adj[maxn];
void dfs(int s, int p){
subtree[s]=1;
for(auto x : adj[s]){
int u = x.first;
if(u==p) continue;
dfs(u,s), subtree[s]+=subtree[u];
}
}
void dfs2(int s, int p, int dep, int weight, bool ok){
if(weight>KK) return;
for(auto u : adj[s])
if(u.first!=p)
dfs2(u.first,s,dep+1,weight+u.second, ok);
int D = KK-weight;
if(!ok){
if(D and a[D]<timer) cnt[D] = cnt[KK+1], a[D]=timer;
answ = min(answ, dep+cnt[D]);
}
else{
if(a[weight]<timer) cnt[weight] = cnt[KK+1];
a[weight]=timer; cnt[weight] = min(cnt[weight], dep);
}
}
int find_centroid(int s, int p, int sz){
for(auto u : adj[s])
if(u.first!=p and subtree[u.first]>sz/2)
return find_centroid(u.first, s, sz);
return s;
}
void centroid_decomp(int s, int p){
dfs(s,-1); int sz = subtree[s];
int centroid = find_centroid(s,-1,sz);
timer++;
for(auto w : adj[centroid]){
int u = w.first; if(u==p) continue;
dfs2(u,centroid,1,w.second,0), dfs2(u,centroid,1,w.second,1);
}
while(!adj[centroid].empty()){
int x = adj[centroid].begin()->first;
adj[x].erase(adj[x].lower_bound({centroid,-1}));
adj[centroid].erase(adj[centroid].begin());
centroid_decomp(x,centroid);
}
}
int best_path(int N, int K, int H[][2], int L[])
{
answ = N+1; KK = K; cnt[0]=0;
for(int i = 1; i <= K+1; i++) cnt[i]=N+1;
for(int i = 0; i < N-1; i++)
adj[++H[i][0]].insert({++H[i][1],L[i]}),
adj[H[i][1]].insert({H[i][0],L[i]});
centroid_decomp(1,-1);
return (answ==N+1?-1:answ);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
7 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9684 KB |
Output is correct |
6 |
Correct |
6 ms |
9684 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
5 ms |
9684 KB |
Output is correct |
9 |
Correct |
6 ms |
9712 KB |
Output is correct |
10 |
Correct |
6 ms |
9708 KB |
Output is correct |
11 |
Correct |
5 ms |
9684 KB |
Output is correct |
12 |
Correct |
7 ms |
9708 KB |
Output is correct |
13 |
Correct |
6 ms |
9716 KB |
Output is correct |
14 |
Correct |
5 ms |
9684 KB |
Output is correct |
15 |
Correct |
6 ms |
9708 KB |
Output is correct |
16 |
Correct |
5 ms |
9684 KB |
Output is correct |
17 |
Correct |
5 ms |
9684 KB |
Output is correct |
18 |
Correct |
5 ms |
9684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
7 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9684 KB |
Output is correct |
6 |
Correct |
6 ms |
9684 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
5 ms |
9684 KB |
Output is correct |
9 |
Correct |
6 ms |
9712 KB |
Output is correct |
10 |
Correct |
6 ms |
9708 KB |
Output is correct |
11 |
Correct |
5 ms |
9684 KB |
Output is correct |
12 |
Correct |
7 ms |
9708 KB |
Output is correct |
13 |
Correct |
6 ms |
9716 KB |
Output is correct |
14 |
Correct |
5 ms |
9684 KB |
Output is correct |
15 |
Correct |
6 ms |
9708 KB |
Output is correct |
16 |
Correct |
5 ms |
9684 KB |
Output is correct |
17 |
Correct |
5 ms |
9684 KB |
Output is correct |
18 |
Correct |
5 ms |
9684 KB |
Output is correct |
19 |
Correct |
5 ms |
9712 KB |
Output is correct |
20 |
Correct |
5 ms |
9684 KB |
Output is correct |
21 |
Correct |
6 ms |
9812 KB |
Output is correct |
22 |
Correct |
10 ms |
16724 KB |
Output is correct |
23 |
Correct |
9 ms |
15444 KB |
Output is correct |
24 |
Correct |
11 ms |
16512 KB |
Output is correct |
25 |
Correct |
10 ms |
16156 KB |
Output is correct |
26 |
Correct |
8 ms |
12372 KB |
Output is correct |
27 |
Correct |
8 ms |
12884 KB |
Output is correct |
28 |
Correct |
7 ms |
11348 KB |
Output is correct |
29 |
Correct |
8 ms |
12280 KB |
Output is correct |
30 |
Correct |
8 ms |
12628 KB |
Output is correct |
31 |
Correct |
9 ms |
14840 KB |
Output is correct |
32 |
Correct |
10 ms |
15292 KB |
Output is correct |
33 |
Correct |
10 ms |
15916 KB |
Output is correct |
34 |
Correct |
9 ms |
14456 KB |
Output is correct |
35 |
Correct |
10 ms |
16096 KB |
Output is correct |
36 |
Correct |
10 ms |
17088 KB |
Output is correct |
37 |
Correct |
10 ms |
15956 KB |
Output is correct |
38 |
Correct |
10 ms |
13688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
7 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9684 KB |
Output is correct |
6 |
Correct |
6 ms |
9684 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
5 ms |
9684 KB |
Output is correct |
9 |
Correct |
6 ms |
9712 KB |
Output is correct |
10 |
Correct |
6 ms |
9708 KB |
Output is correct |
11 |
Correct |
5 ms |
9684 KB |
Output is correct |
12 |
Correct |
7 ms |
9708 KB |
Output is correct |
13 |
Correct |
6 ms |
9716 KB |
Output is correct |
14 |
Correct |
5 ms |
9684 KB |
Output is correct |
15 |
Correct |
6 ms |
9708 KB |
Output is correct |
16 |
Correct |
5 ms |
9684 KB |
Output is correct |
17 |
Correct |
5 ms |
9684 KB |
Output is correct |
18 |
Correct |
5 ms |
9684 KB |
Output is correct |
19 |
Correct |
188 ms |
20716 KB |
Output is correct |
20 |
Correct |
184 ms |
20680 KB |
Output is correct |
21 |
Correct |
211 ms |
20748 KB |
Output is correct |
22 |
Correct |
206 ms |
20812 KB |
Output is correct |
23 |
Correct |
107 ms |
20800 KB |
Output is correct |
24 |
Correct |
89 ms |
20800 KB |
Output is correct |
25 |
Correct |
181 ms |
24924 KB |
Output is correct |
26 |
Correct |
132 ms |
28676 KB |
Output is correct |
27 |
Correct |
280 ms |
31648 KB |
Output is correct |
28 |
Correct |
383 ms |
47324 KB |
Output is correct |
29 |
Correct |
354 ms |
46208 KB |
Output is correct |
30 |
Correct |
264 ms |
31668 KB |
Output is correct |
31 |
Correct |
263 ms |
31852 KB |
Output is correct |
32 |
Correct |
315 ms |
31564 KB |
Output is correct |
33 |
Correct |
307 ms |
31752 KB |
Output is correct |
34 |
Correct |
258 ms |
31900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
7 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9684 KB |
Output is correct |
6 |
Correct |
6 ms |
9684 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
5 ms |
9684 KB |
Output is correct |
9 |
Correct |
6 ms |
9712 KB |
Output is correct |
10 |
Correct |
6 ms |
9708 KB |
Output is correct |
11 |
Correct |
5 ms |
9684 KB |
Output is correct |
12 |
Correct |
7 ms |
9708 KB |
Output is correct |
13 |
Correct |
6 ms |
9716 KB |
Output is correct |
14 |
Correct |
5 ms |
9684 KB |
Output is correct |
15 |
Correct |
6 ms |
9708 KB |
Output is correct |
16 |
Correct |
5 ms |
9684 KB |
Output is correct |
17 |
Correct |
5 ms |
9684 KB |
Output is correct |
18 |
Correct |
5 ms |
9684 KB |
Output is correct |
19 |
Correct |
5 ms |
9712 KB |
Output is correct |
20 |
Correct |
5 ms |
9684 KB |
Output is correct |
21 |
Correct |
6 ms |
9812 KB |
Output is correct |
22 |
Correct |
10 ms |
16724 KB |
Output is correct |
23 |
Correct |
9 ms |
15444 KB |
Output is correct |
24 |
Correct |
11 ms |
16512 KB |
Output is correct |
25 |
Correct |
10 ms |
16156 KB |
Output is correct |
26 |
Correct |
8 ms |
12372 KB |
Output is correct |
27 |
Correct |
8 ms |
12884 KB |
Output is correct |
28 |
Correct |
7 ms |
11348 KB |
Output is correct |
29 |
Correct |
8 ms |
12280 KB |
Output is correct |
30 |
Correct |
8 ms |
12628 KB |
Output is correct |
31 |
Correct |
9 ms |
14840 KB |
Output is correct |
32 |
Correct |
10 ms |
15292 KB |
Output is correct |
33 |
Correct |
10 ms |
15916 KB |
Output is correct |
34 |
Correct |
9 ms |
14456 KB |
Output is correct |
35 |
Correct |
10 ms |
16096 KB |
Output is correct |
36 |
Correct |
10 ms |
17088 KB |
Output is correct |
37 |
Correct |
10 ms |
15956 KB |
Output is correct |
38 |
Correct |
10 ms |
13688 KB |
Output is correct |
39 |
Correct |
188 ms |
20716 KB |
Output is correct |
40 |
Correct |
184 ms |
20680 KB |
Output is correct |
41 |
Correct |
211 ms |
20748 KB |
Output is correct |
42 |
Correct |
206 ms |
20812 KB |
Output is correct |
43 |
Correct |
107 ms |
20800 KB |
Output is correct |
44 |
Correct |
89 ms |
20800 KB |
Output is correct |
45 |
Correct |
181 ms |
24924 KB |
Output is correct |
46 |
Correct |
132 ms |
28676 KB |
Output is correct |
47 |
Correct |
280 ms |
31648 KB |
Output is correct |
48 |
Correct |
383 ms |
47324 KB |
Output is correct |
49 |
Correct |
354 ms |
46208 KB |
Output is correct |
50 |
Correct |
264 ms |
31668 KB |
Output is correct |
51 |
Correct |
263 ms |
31852 KB |
Output is correct |
52 |
Correct |
315 ms |
31564 KB |
Output is correct |
53 |
Correct |
307 ms |
31752 KB |
Output is correct |
54 |
Correct |
258 ms |
31900 KB |
Output is correct |
55 |
Correct |
16 ms |
10964 KB |
Output is correct |
56 |
Correct |
17 ms |
10944 KB |
Output is correct |
57 |
Correct |
106 ms |
20808 KB |
Output is correct |
58 |
Correct |
69 ms |
20844 KB |
Output is correct |
59 |
Correct |
123 ms |
29936 KB |
Output is correct |
60 |
Correct |
672 ms |
56868 KB |
Output is correct |
61 |
Correct |
273 ms |
34632 KB |
Output is correct |
62 |
Correct |
294 ms |
38448 KB |
Output is correct |
63 |
Correct |
387 ms |
38604 KB |
Output is correct |
64 |
Correct |
660 ms |
39048 KB |
Output is correct |
65 |
Correct |
311 ms |
35412 KB |
Output is correct |
66 |
Correct |
532 ms |
54632 KB |
Output is correct |
67 |
Correct |
309 ms |
38900 KB |
Output is correct |
68 |
Correct |
411 ms |
41348 KB |
Output is correct |
69 |
Correct |
410 ms |
41748 KB |
Output is correct |
70 |
Correct |
394 ms |
40172 KB |
Output is correct |