# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1115746 |
2024-11-20T22:03:17 Z |
lambd47 |
Race (IOI11_race) |
C++14 |
|
247 ms |
113596 KB |
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
const int MX=2e5+6;
vector<pair<int,int>> adj[MX];
vector<pair<int,int>> vec;
vector<int> limpa;
bool marc[MX];
int sz[MX];
int p[100*MX];
int k;
int n;
int dfssz(int node, int pai){
sz[node]=1;
for(auto [a,_]: adj[node]){
if(a==pai || marc[a])continue;
sz[node]+=dfssz(a,node);
}
return sz[node];
}
int findcent(int node, int s, int pai){
for(auto [a,_]: adj[node]){
if(a==pai || marc[a])continue;
if((2*sz[a])>s)return findcent(a,s,node);
}
return node;
}
void dfs(int node, int pai, int d,int prof){
if(d>k)return;
vec.push_back({d,prof});
limpa.push_back(d);
for(auto [a,w]:adj[node]){
if(a==pai || marc[a])continue;
dfs(a,node,d+w,prof+1);
}
}
int resp;
void centroidDecomp(int node){
int s=dfssz(node,node);
node=findcent(node,s,node);
marc[node]=1;
p[0]=0;
for(auto [a,w]: adj[node]){
if(marc[a])continue;
vec.clear();
dfs(a,node,w,1);
for(auto [d,prof]:vec){
if(k>=d && p[k-d]!=MOD){
resp=min(resp,prof+p[k-d]);
}
}
for(auto [d,prof]:vec){
p[d]=min(p[d],prof);
}
}
for(auto a: limpa){
p[a]=MOD;
}
limpa.clear();
for(auto [a,_]:adj[node]){
if(marc[a])continue;
centroidDecomp(a);
}
}
int best_path(int N, int K, int H[][2], int L[])
{
k=K;
n=N;
resp=MOD;
for(int i=1;i<100*MX;i++)p[i]=MOD;
for(int i=0;i<n-1;i++){
int a=H[i][0],b=H[i][1];
adj[a].push_back({b,L[i]});
adj[b].push_back({a,L[i]});
}
centroidDecomp(0);
if(resp==MOD)return -1;
return resp;
}
Compilation message
race.cpp: In function 'int dfssz(int, int)':
race.cpp:20:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
20 | for(auto [a,_]: adj[node]){
| ^
race.cpp: In function 'int findcent(int, int, int)':
race.cpp:29:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
29 | for(auto [a,_]: adj[node]){
| ^
race.cpp: In function 'void dfs(int, int, int, int)':
race.cpp:40:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
40 | for(auto [a,w]:adj[node]){
| ^
race.cpp: In function 'void centroidDecomp(int)':
race.cpp:56:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
56 | for(auto [a,w]: adj[node]){
| ^
race.cpp:60:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
60 | for(auto [d,prof]:vec){
| ^
race.cpp:65:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
65 | for(auto [d,prof]:vec){
| ^
race.cpp:74:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
74 | for(auto [a,_]:adj[node]){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
87624 KB |
Output is correct |
2 |
Correct |
34 ms |
87888 KB |
Output is correct |
3 |
Correct |
44 ms |
87636 KB |
Output is correct |
4 |
Correct |
45 ms |
87872 KB |
Output is correct |
5 |
Correct |
48 ms |
87628 KB |
Output is correct |
6 |
Correct |
59 ms |
87668 KB |
Output is correct |
7 |
Correct |
37 ms |
87728 KB |
Output is correct |
8 |
Correct |
35 ms |
87636 KB |
Output is correct |
9 |
Correct |
47 ms |
87624 KB |
Output is correct |
10 |
Correct |
37 ms |
87876 KB |
Output is correct |
11 |
Correct |
41 ms |
87884 KB |
Output is correct |
12 |
Correct |
50 ms |
87624 KB |
Output is correct |
13 |
Correct |
37 ms |
87784 KB |
Output is correct |
14 |
Correct |
35 ms |
87736 KB |
Output is correct |
15 |
Correct |
36 ms |
87848 KB |
Output is correct |
16 |
Correct |
40 ms |
87664 KB |
Output is correct |
17 |
Correct |
45 ms |
87880 KB |
Output is correct |
18 |
Correct |
37 ms |
87812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
87624 KB |
Output is correct |
2 |
Correct |
34 ms |
87888 KB |
Output is correct |
3 |
Correct |
44 ms |
87636 KB |
Output is correct |
4 |
Correct |
45 ms |
87872 KB |
Output is correct |
5 |
Correct |
48 ms |
87628 KB |
Output is correct |
6 |
Correct |
59 ms |
87668 KB |
Output is correct |
7 |
Correct |
37 ms |
87728 KB |
Output is correct |
8 |
Correct |
35 ms |
87636 KB |
Output is correct |
9 |
Correct |
47 ms |
87624 KB |
Output is correct |
10 |
Correct |
37 ms |
87876 KB |
Output is correct |
11 |
Correct |
41 ms |
87884 KB |
Output is correct |
12 |
Correct |
50 ms |
87624 KB |
Output is correct |
13 |
Correct |
37 ms |
87784 KB |
Output is correct |
14 |
Correct |
35 ms |
87736 KB |
Output is correct |
15 |
Correct |
36 ms |
87848 KB |
Output is correct |
16 |
Correct |
40 ms |
87664 KB |
Output is correct |
17 |
Correct |
45 ms |
87880 KB |
Output is correct |
18 |
Correct |
37 ms |
87812 KB |
Output is correct |
19 |
Correct |
34 ms |
87624 KB |
Output is correct |
20 |
Correct |
33 ms |
87856 KB |
Output is correct |
21 |
Correct |
35 ms |
87880 KB |
Output is correct |
22 |
Correct |
38 ms |
87880 KB |
Output is correct |
23 |
Correct |
41 ms |
87924 KB |
Output is correct |
24 |
Correct |
37 ms |
87888 KB |
Output is correct |
25 |
Correct |
40 ms |
87700 KB |
Output is correct |
26 |
Correct |
36 ms |
87924 KB |
Output is correct |
27 |
Correct |
40 ms |
87880 KB |
Output is correct |
28 |
Correct |
36 ms |
87880 KB |
Output is correct |
29 |
Correct |
34 ms |
87880 KB |
Output is correct |
30 |
Correct |
34 ms |
87888 KB |
Output is correct |
31 |
Correct |
36 ms |
87880 KB |
Output is correct |
32 |
Correct |
34 ms |
87788 KB |
Output is correct |
33 |
Correct |
31 ms |
87880 KB |
Output is correct |
34 |
Correct |
33 ms |
87880 KB |
Output is correct |
35 |
Correct |
35 ms |
87880 KB |
Output is correct |
36 |
Correct |
32 ms |
87888 KB |
Output is correct |
37 |
Correct |
35 ms |
87880 KB |
Output is correct |
38 |
Correct |
32 ms |
87880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
87624 KB |
Output is correct |
2 |
Correct |
34 ms |
87888 KB |
Output is correct |
3 |
Correct |
44 ms |
87636 KB |
Output is correct |
4 |
Correct |
45 ms |
87872 KB |
Output is correct |
5 |
Correct |
48 ms |
87628 KB |
Output is correct |
6 |
Correct |
59 ms |
87668 KB |
Output is correct |
7 |
Correct |
37 ms |
87728 KB |
Output is correct |
8 |
Correct |
35 ms |
87636 KB |
Output is correct |
9 |
Correct |
47 ms |
87624 KB |
Output is correct |
10 |
Correct |
37 ms |
87876 KB |
Output is correct |
11 |
Correct |
41 ms |
87884 KB |
Output is correct |
12 |
Correct |
50 ms |
87624 KB |
Output is correct |
13 |
Correct |
37 ms |
87784 KB |
Output is correct |
14 |
Correct |
35 ms |
87736 KB |
Output is correct |
15 |
Correct |
36 ms |
87848 KB |
Output is correct |
16 |
Correct |
40 ms |
87664 KB |
Output is correct |
17 |
Correct |
45 ms |
87880 KB |
Output is correct |
18 |
Correct |
37 ms |
87812 KB |
Output is correct |
19 |
Correct |
92 ms |
95212 KB |
Output is correct |
20 |
Correct |
102 ms |
95312 KB |
Output is correct |
21 |
Correct |
109 ms |
95792 KB |
Output is correct |
22 |
Correct |
103 ms |
96256 KB |
Output is correct |
23 |
Correct |
73 ms |
95564 KB |
Output is correct |
24 |
Correct |
70 ms |
95304 KB |
Output is correct |
25 |
Correct |
108 ms |
97844 KB |
Output is correct |
26 |
Correct |
101 ms |
101956 KB |
Output is correct |
27 |
Correct |
127 ms |
100680 KB |
Output is correct |
28 |
Correct |
191 ms |
112204 KB |
Output is correct |
29 |
Correct |
179 ms |
110924 KB |
Output is correct |
30 |
Correct |
137 ms |
100676 KB |
Output is correct |
31 |
Correct |
127 ms |
100704 KB |
Output is correct |
32 |
Correct |
144 ms |
100780 KB |
Output is correct |
33 |
Correct |
152 ms |
99428 KB |
Output is correct |
34 |
Correct |
153 ms |
100448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
87624 KB |
Output is correct |
2 |
Correct |
34 ms |
87888 KB |
Output is correct |
3 |
Correct |
44 ms |
87636 KB |
Output is correct |
4 |
Correct |
45 ms |
87872 KB |
Output is correct |
5 |
Correct |
48 ms |
87628 KB |
Output is correct |
6 |
Correct |
59 ms |
87668 KB |
Output is correct |
7 |
Correct |
37 ms |
87728 KB |
Output is correct |
8 |
Correct |
35 ms |
87636 KB |
Output is correct |
9 |
Correct |
47 ms |
87624 KB |
Output is correct |
10 |
Correct |
37 ms |
87876 KB |
Output is correct |
11 |
Correct |
41 ms |
87884 KB |
Output is correct |
12 |
Correct |
50 ms |
87624 KB |
Output is correct |
13 |
Correct |
37 ms |
87784 KB |
Output is correct |
14 |
Correct |
35 ms |
87736 KB |
Output is correct |
15 |
Correct |
36 ms |
87848 KB |
Output is correct |
16 |
Correct |
40 ms |
87664 KB |
Output is correct |
17 |
Correct |
45 ms |
87880 KB |
Output is correct |
18 |
Correct |
37 ms |
87812 KB |
Output is correct |
19 |
Correct |
34 ms |
87624 KB |
Output is correct |
20 |
Correct |
33 ms |
87856 KB |
Output is correct |
21 |
Correct |
35 ms |
87880 KB |
Output is correct |
22 |
Correct |
38 ms |
87880 KB |
Output is correct |
23 |
Correct |
41 ms |
87924 KB |
Output is correct |
24 |
Correct |
37 ms |
87888 KB |
Output is correct |
25 |
Correct |
40 ms |
87700 KB |
Output is correct |
26 |
Correct |
36 ms |
87924 KB |
Output is correct |
27 |
Correct |
40 ms |
87880 KB |
Output is correct |
28 |
Correct |
36 ms |
87880 KB |
Output is correct |
29 |
Correct |
34 ms |
87880 KB |
Output is correct |
30 |
Correct |
34 ms |
87888 KB |
Output is correct |
31 |
Correct |
36 ms |
87880 KB |
Output is correct |
32 |
Correct |
34 ms |
87788 KB |
Output is correct |
33 |
Correct |
31 ms |
87880 KB |
Output is correct |
34 |
Correct |
33 ms |
87880 KB |
Output is correct |
35 |
Correct |
35 ms |
87880 KB |
Output is correct |
36 |
Correct |
32 ms |
87888 KB |
Output is correct |
37 |
Correct |
35 ms |
87880 KB |
Output is correct |
38 |
Correct |
32 ms |
87880 KB |
Output is correct |
39 |
Correct |
92 ms |
95212 KB |
Output is correct |
40 |
Correct |
102 ms |
95312 KB |
Output is correct |
41 |
Correct |
109 ms |
95792 KB |
Output is correct |
42 |
Correct |
103 ms |
96256 KB |
Output is correct |
43 |
Correct |
73 ms |
95564 KB |
Output is correct |
44 |
Correct |
70 ms |
95304 KB |
Output is correct |
45 |
Correct |
108 ms |
97844 KB |
Output is correct |
46 |
Correct |
101 ms |
101956 KB |
Output is correct |
47 |
Correct |
127 ms |
100680 KB |
Output is correct |
48 |
Correct |
191 ms |
112204 KB |
Output is correct |
49 |
Correct |
179 ms |
110924 KB |
Output is correct |
50 |
Correct |
137 ms |
100676 KB |
Output is correct |
51 |
Correct |
127 ms |
100704 KB |
Output is correct |
52 |
Correct |
144 ms |
100780 KB |
Output is correct |
53 |
Correct |
152 ms |
99428 KB |
Output is correct |
54 |
Correct |
153 ms |
100448 KB |
Output is correct |
55 |
Correct |
40 ms |
88392 KB |
Output is correct |
56 |
Correct |
45 ms |
88396 KB |
Output is correct |
57 |
Correct |
83 ms |
96352 KB |
Output is correct |
58 |
Correct |
56 ms |
95932 KB |
Output is correct |
59 |
Correct |
103 ms |
101956 KB |
Output is correct |
60 |
Correct |
247 ms |
113596 KB |
Output is correct |
61 |
Correct |
136 ms |
101196 KB |
Output is correct |
62 |
Correct |
152 ms |
101868 KB |
Output is correct |
63 |
Correct |
167 ms |
101964 KB |
Output is correct |
64 |
Correct |
218 ms |
103108 KB |
Output is correct |
65 |
Correct |
138 ms |
101608 KB |
Output is correct |
66 |
Correct |
226 ms |
109128 KB |
Output is correct |
67 |
Correct |
90 ms |
103096 KB |
Output is correct |
68 |
Correct |
183 ms |
102108 KB |
Output is correct |
69 |
Correct |
159 ms |
102376 KB |
Output is correct |
70 |
Correct |
152 ms |
101828 KB |
Output is correct |