# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1055404 |
2024-08-12T18:46:51 Z |
E_rK |
Race (IOI11_race) |
C++14 |
|
247 ms |
46744 KB |
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
#define MAXN 200005
#define pb push_back
#define fi first
#define se second
typedef long long int lo;
lo k;
vector<pair<lo,lo> > v[MAXN];
lo vis[MAXN];
lo sub[MAXN];
lo mpp[1000005];
lo ans;
void dfs(lo node, lo par)
{
sub[node] = 1;
for(auto e: v[node]){
if(e.fi == par or vis[e.fi])
continue;
dfs(e.fi,node);
sub[node] += sub[e.fi];
}
}
lo centroid(lo node, lo par, lo val){
for(auto e: v[node]){
if(e.fi == par or vis[e.fi])
continue;
if(sub[e.fi] >= val/2)
return centroid(e.fi,node,val);
}
return node;
}
void check(lo node, lo par, lo cost,lo num){
if(cost > k)
return;
if(mpp[k-cost] != -1)
ans = min(ans, mpp[k-cost] + num);
for(auto e: v[node]){
if(e.fi == par or vis[e.fi])
continue;
check(e.fi,node,cost+e.se,num+1);
}
}
void build(lo node, lo par, lo cost,lo num){
if(cost > k)
return;
if(mpp[cost] == -1)
mpp[cost] = num;
else
mpp[cost] = min(num,mpp[cost]);
for(auto e: v[node]){
if(e.fi == par or vis[e.fi])
continue;
build(e.fi,node,cost+e.se,num+1);
}
}
void sifirla(lo node, lo par, lo cost){
if(cost > k)
return;
mpp[cost] = -1;
for(auto e:v[node]){
if(e.fi == par || vis[e.fi])continue;
sifirla(e.fi,node,cost+e.se);
}
}
void solve(lo node)
{
dfs(node,-1);
lo c = centroid(node,-1,sub[node]);
mpp[0] = 0;
for(auto e: v[c]){
if(vis[e.fi])
continue;
check(e.fi,c,e.se,1);
build(e.fi,c,e.se,1);
}
for(auto e: v[c]){
if(vis[e.fi])
continue;
sifirla(e.fi,c,e.se);
}
vis[c]=1;
for(auto e: v[c]){
if(vis[e.fi])
continue;
solve(e.fi);
}
}
int best_path(int N, int K, int H[][2], int L[])
{
k = K;
memset(mpp,-1,sizeof(mpp));
for (int i = 0; i < N-1; ++i)
{
v[H[i][0]].pb({H[i][1],L[i]});
v[H[i][1]].pb({H[i][0],L[i]});
}
ans = N+5;
solve(0);
if(ans == N+5)
ans = -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
17496 KB |
Output is correct |
2 |
Correct |
2 ms |
17500 KB |
Output is correct |
3 |
Correct |
2 ms |
17500 KB |
Output is correct |
4 |
Correct |
2 ms |
17500 KB |
Output is correct |
5 |
Correct |
2 ms |
17500 KB |
Output is correct |
6 |
Correct |
2 ms |
17500 KB |
Output is correct |
7 |
Correct |
2 ms |
17500 KB |
Output is correct |
8 |
Correct |
2 ms |
17500 KB |
Output is correct |
9 |
Correct |
2 ms |
17500 KB |
Output is correct |
10 |
Correct |
2 ms |
17500 KB |
Output is correct |
11 |
Correct |
2 ms |
17500 KB |
Output is correct |
12 |
Correct |
2 ms |
17500 KB |
Output is correct |
13 |
Correct |
2 ms |
17500 KB |
Output is correct |
14 |
Correct |
2 ms |
17500 KB |
Output is correct |
15 |
Correct |
2 ms |
17500 KB |
Output is correct |
16 |
Correct |
2 ms |
17500 KB |
Output is correct |
17 |
Correct |
2 ms |
17500 KB |
Output is correct |
18 |
Correct |
2 ms |
17500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
17496 KB |
Output is correct |
2 |
Correct |
2 ms |
17500 KB |
Output is correct |
3 |
Correct |
2 ms |
17500 KB |
Output is correct |
4 |
Correct |
2 ms |
17500 KB |
Output is correct |
5 |
Correct |
2 ms |
17500 KB |
Output is correct |
6 |
Correct |
2 ms |
17500 KB |
Output is correct |
7 |
Correct |
2 ms |
17500 KB |
Output is correct |
8 |
Correct |
2 ms |
17500 KB |
Output is correct |
9 |
Correct |
2 ms |
17500 KB |
Output is correct |
10 |
Correct |
2 ms |
17500 KB |
Output is correct |
11 |
Correct |
2 ms |
17500 KB |
Output is correct |
12 |
Correct |
2 ms |
17500 KB |
Output is correct |
13 |
Correct |
2 ms |
17500 KB |
Output is correct |
14 |
Correct |
2 ms |
17500 KB |
Output is correct |
15 |
Correct |
2 ms |
17500 KB |
Output is correct |
16 |
Correct |
2 ms |
17500 KB |
Output is correct |
17 |
Correct |
2 ms |
17500 KB |
Output is correct |
18 |
Correct |
2 ms |
17500 KB |
Output is correct |
19 |
Correct |
2 ms |
17500 KB |
Output is correct |
20 |
Correct |
2 ms |
17692 KB |
Output is correct |
21 |
Correct |
2 ms |
17500 KB |
Output is correct |
22 |
Correct |
2 ms |
17756 KB |
Output is correct |
23 |
Correct |
2 ms |
17500 KB |
Output is correct |
24 |
Correct |
2 ms |
17500 KB |
Output is correct |
25 |
Correct |
2 ms |
17500 KB |
Output is correct |
26 |
Correct |
2 ms |
17500 KB |
Output is correct |
27 |
Correct |
2 ms |
17500 KB |
Output is correct |
28 |
Correct |
2 ms |
17700 KB |
Output is correct |
29 |
Correct |
3 ms |
18008 KB |
Output is correct |
30 |
Correct |
2 ms |
17756 KB |
Output is correct |
31 |
Correct |
2 ms |
17680 KB |
Output is correct |
32 |
Correct |
2 ms |
17500 KB |
Output is correct |
33 |
Correct |
3 ms |
17500 KB |
Output is correct |
34 |
Correct |
2 ms |
17500 KB |
Output is correct |
35 |
Correct |
2 ms |
17500 KB |
Output is correct |
36 |
Correct |
2 ms |
17756 KB |
Output is correct |
37 |
Correct |
2 ms |
17496 KB |
Output is correct |
38 |
Correct |
2 ms |
17500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
17496 KB |
Output is correct |
2 |
Correct |
2 ms |
17500 KB |
Output is correct |
3 |
Correct |
2 ms |
17500 KB |
Output is correct |
4 |
Correct |
2 ms |
17500 KB |
Output is correct |
5 |
Correct |
2 ms |
17500 KB |
Output is correct |
6 |
Correct |
2 ms |
17500 KB |
Output is correct |
7 |
Correct |
2 ms |
17500 KB |
Output is correct |
8 |
Correct |
2 ms |
17500 KB |
Output is correct |
9 |
Correct |
2 ms |
17500 KB |
Output is correct |
10 |
Correct |
2 ms |
17500 KB |
Output is correct |
11 |
Correct |
2 ms |
17500 KB |
Output is correct |
12 |
Correct |
2 ms |
17500 KB |
Output is correct |
13 |
Correct |
2 ms |
17500 KB |
Output is correct |
14 |
Correct |
2 ms |
17500 KB |
Output is correct |
15 |
Correct |
2 ms |
17500 KB |
Output is correct |
16 |
Correct |
2 ms |
17500 KB |
Output is correct |
17 |
Correct |
2 ms |
17500 KB |
Output is correct |
18 |
Correct |
2 ms |
17500 KB |
Output is correct |
19 |
Correct |
70 ms |
25560 KB |
Output is correct |
20 |
Correct |
67 ms |
25768 KB |
Output is correct |
21 |
Correct |
77 ms |
25680 KB |
Output is correct |
22 |
Correct |
66 ms |
25680 KB |
Output is correct |
23 |
Correct |
33 ms |
26028 KB |
Output is correct |
24 |
Correct |
29 ms |
26716 KB |
Output is correct |
25 |
Correct |
68 ms |
29952 KB |
Output is correct |
26 |
Correct |
60 ms |
32852 KB |
Output is correct |
27 |
Correct |
78 ms |
35408 KB |
Output is correct |
28 |
Correct |
119 ms |
46744 KB |
Output is correct |
29 |
Correct |
116 ms |
45852 KB |
Output is correct |
30 |
Correct |
87 ms |
35496 KB |
Output is correct |
31 |
Correct |
82 ms |
35408 KB |
Output is correct |
32 |
Correct |
84 ms |
35664 KB |
Output is correct |
33 |
Correct |
107 ms |
34204 KB |
Output is correct |
34 |
Correct |
82 ms |
35156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
17496 KB |
Output is correct |
2 |
Correct |
2 ms |
17500 KB |
Output is correct |
3 |
Correct |
2 ms |
17500 KB |
Output is correct |
4 |
Correct |
2 ms |
17500 KB |
Output is correct |
5 |
Correct |
2 ms |
17500 KB |
Output is correct |
6 |
Correct |
2 ms |
17500 KB |
Output is correct |
7 |
Correct |
2 ms |
17500 KB |
Output is correct |
8 |
Correct |
2 ms |
17500 KB |
Output is correct |
9 |
Correct |
2 ms |
17500 KB |
Output is correct |
10 |
Correct |
2 ms |
17500 KB |
Output is correct |
11 |
Correct |
2 ms |
17500 KB |
Output is correct |
12 |
Correct |
2 ms |
17500 KB |
Output is correct |
13 |
Correct |
2 ms |
17500 KB |
Output is correct |
14 |
Correct |
2 ms |
17500 KB |
Output is correct |
15 |
Correct |
2 ms |
17500 KB |
Output is correct |
16 |
Correct |
2 ms |
17500 KB |
Output is correct |
17 |
Correct |
2 ms |
17500 KB |
Output is correct |
18 |
Correct |
2 ms |
17500 KB |
Output is correct |
19 |
Correct |
2 ms |
17500 KB |
Output is correct |
20 |
Correct |
2 ms |
17692 KB |
Output is correct |
21 |
Correct |
2 ms |
17500 KB |
Output is correct |
22 |
Correct |
2 ms |
17756 KB |
Output is correct |
23 |
Correct |
2 ms |
17500 KB |
Output is correct |
24 |
Correct |
2 ms |
17500 KB |
Output is correct |
25 |
Correct |
2 ms |
17500 KB |
Output is correct |
26 |
Correct |
2 ms |
17500 KB |
Output is correct |
27 |
Correct |
2 ms |
17500 KB |
Output is correct |
28 |
Correct |
2 ms |
17700 KB |
Output is correct |
29 |
Correct |
3 ms |
18008 KB |
Output is correct |
30 |
Correct |
2 ms |
17756 KB |
Output is correct |
31 |
Correct |
2 ms |
17680 KB |
Output is correct |
32 |
Correct |
2 ms |
17500 KB |
Output is correct |
33 |
Correct |
3 ms |
17500 KB |
Output is correct |
34 |
Correct |
2 ms |
17500 KB |
Output is correct |
35 |
Correct |
2 ms |
17500 KB |
Output is correct |
36 |
Correct |
2 ms |
17756 KB |
Output is correct |
37 |
Correct |
2 ms |
17496 KB |
Output is correct |
38 |
Correct |
2 ms |
17500 KB |
Output is correct |
39 |
Correct |
70 ms |
25560 KB |
Output is correct |
40 |
Correct |
67 ms |
25768 KB |
Output is correct |
41 |
Correct |
77 ms |
25680 KB |
Output is correct |
42 |
Correct |
66 ms |
25680 KB |
Output is correct |
43 |
Correct |
33 ms |
26028 KB |
Output is correct |
44 |
Correct |
29 ms |
26716 KB |
Output is correct |
45 |
Correct |
68 ms |
29952 KB |
Output is correct |
46 |
Correct |
60 ms |
32852 KB |
Output is correct |
47 |
Correct |
78 ms |
35408 KB |
Output is correct |
48 |
Correct |
119 ms |
46744 KB |
Output is correct |
49 |
Correct |
116 ms |
45852 KB |
Output is correct |
50 |
Correct |
87 ms |
35496 KB |
Output is correct |
51 |
Correct |
82 ms |
35408 KB |
Output is correct |
52 |
Correct |
84 ms |
35664 KB |
Output is correct |
53 |
Correct |
107 ms |
34204 KB |
Output is correct |
54 |
Correct |
82 ms |
35156 KB |
Output is correct |
55 |
Correct |
7 ms |
18268 KB |
Output is correct |
56 |
Correct |
7 ms |
18356 KB |
Output is correct |
57 |
Correct |
37 ms |
27352 KB |
Output is correct |
58 |
Correct |
19 ms |
26308 KB |
Output is correct |
59 |
Correct |
56 ms |
32964 KB |
Output is correct |
60 |
Correct |
225 ms |
46024 KB |
Output is correct |
61 |
Correct |
86 ms |
35564 KB |
Output is correct |
62 |
Correct |
105 ms |
35412 KB |
Output is correct |
63 |
Correct |
114 ms |
35476 KB |
Output is correct |
64 |
Correct |
247 ms |
35408 KB |
Output is correct |
65 |
Correct |
84 ms |
35864 KB |
Output is correct |
66 |
Correct |
170 ms |
43856 KB |
Output is correct |
67 |
Correct |
47 ms |
34492 KB |
Output is correct |
68 |
Correct |
101 ms |
35860 KB |
Output is correct |
69 |
Correct |
103 ms |
35664 KB |
Output is correct |
70 |
Correct |
95 ms |
34968 KB |
Output is correct |