# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1076653 |
2024-08-26T15:20:00 Z |
rayan_bd |
Race (IOI11_race) |
C++17 |
|
3000 ms |
23120 KB |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int mxN = 2e5+10;
const int INF = (int)1e9;
vector<pair<int,int>> adj[mxN];
int sz[mxN],N,K,ans=INF;
bool ok[mxN];
vector<int> mnDist((int)1e6+50,INF);
void dfs1(int node,int par){
sz[node]=0;
for(auto it:adj[node]){
if(it.first==par||ok[it.first]) continue;
dfs1(it.first,node);
sz[node]+=sz[it.first];
}
sz[node]++;
}
int find(int node,int par){
for(auto it:adj[node]){
if(it.first==par||ok[it.first]) continue;
if(sz[it.first]>=((N+1)/2)){
return find(it.first,node);
}
}
return node;
}
void dfs2(int src,int par,int dist,int h,bool f){
if(dist>K) return;
if(f){
mnDist[dist]=min(mnDist[dist],h);
}else{
ans=min(ans,mnDist[K-dist]+h);
}
for(auto it:adj[src]){
if(!ok[it.first]&&it.first!=par){
dfs2(it.first,src,dist+it.second,h+1,f);
}
}
}
void res(int u,int p,int dist){
if(dist>K) return;
mnDist[dist]=INF;
for(auto it:adj[u]){
if(it.first!=p&&!ok[it.first]){
res(it.first,u,dist+it.second);
}
}
}
void decompose(int u){
dfs1(u,-1);
int cen=find(u,-1);
mnDist[0]=0;
for(auto it:adj[u]){
if(!ok[it.first]){
dfs2(it.first,u,it.second,1,0);
dfs2(it.first,u,it.second,1,1);
}
}
res(u,-1,0);
ok[u]=1;
for(auto it:adj[u]){
if(!ok[it.first]){
decompose(it.first);
}
}
}
int best_path(int n,int k,int h[][2],int l[]){
for(int i=0;i<n-1;++i){
adj[h[i][0]].pb({h[i][1],l[i]});
adj[h[i][1]].pb({h[i][0],l[i]});
}
N=n,K=k;
decompose(0);
return ans>=INF?-1:ans;
}
Compilation message
race.cpp: In function 'void decompose(int)':
race.cpp:60:9: warning: unused variable 'cen' [-Wunused-variable]
60 | int cen=find(u,-1);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
13660 KB |
Output is correct |
2 |
Correct |
3 ms |
13660 KB |
Output is correct |
3 |
Correct |
3 ms |
13660 KB |
Output is correct |
4 |
Correct |
3 ms |
13656 KB |
Output is correct |
5 |
Correct |
3 ms |
13656 KB |
Output is correct |
6 |
Correct |
4 ms |
13660 KB |
Output is correct |
7 |
Correct |
4 ms |
13660 KB |
Output is correct |
8 |
Correct |
4 ms |
13660 KB |
Output is correct |
9 |
Correct |
4 ms |
13660 KB |
Output is correct |
10 |
Correct |
4 ms |
13500 KB |
Output is correct |
11 |
Correct |
4 ms |
13660 KB |
Output is correct |
12 |
Correct |
3 ms |
13660 KB |
Output is correct |
13 |
Correct |
3 ms |
13660 KB |
Output is correct |
14 |
Correct |
4 ms |
13660 KB |
Output is correct |
15 |
Correct |
4 ms |
13660 KB |
Output is correct |
16 |
Correct |
3 ms |
13656 KB |
Output is correct |
17 |
Correct |
4 ms |
13660 KB |
Output is correct |
18 |
Correct |
3 ms |
13656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
13660 KB |
Output is correct |
2 |
Correct |
3 ms |
13660 KB |
Output is correct |
3 |
Correct |
3 ms |
13660 KB |
Output is correct |
4 |
Correct |
3 ms |
13656 KB |
Output is correct |
5 |
Correct |
3 ms |
13656 KB |
Output is correct |
6 |
Correct |
4 ms |
13660 KB |
Output is correct |
7 |
Correct |
4 ms |
13660 KB |
Output is correct |
8 |
Correct |
4 ms |
13660 KB |
Output is correct |
9 |
Correct |
4 ms |
13660 KB |
Output is correct |
10 |
Correct |
4 ms |
13500 KB |
Output is correct |
11 |
Correct |
4 ms |
13660 KB |
Output is correct |
12 |
Correct |
3 ms |
13660 KB |
Output is correct |
13 |
Correct |
3 ms |
13660 KB |
Output is correct |
14 |
Correct |
4 ms |
13660 KB |
Output is correct |
15 |
Correct |
4 ms |
13660 KB |
Output is correct |
16 |
Correct |
3 ms |
13656 KB |
Output is correct |
17 |
Correct |
4 ms |
13660 KB |
Output is correct |
18 |
Correct |
3 ms |
13656 KB |
Output is correct |
19 |
Correct |
5 ms |
13660 KB |
Output is correct |
20 |
Correct |
4 ms |
13656 KB |
Output is correct |
21 |
Correct |
4 ms |
13564 KB |
Output is correct |
22 |
Correct |
4 ms |
13660 KB |
Output is correct |
23 |
Correct |
4 ms |
13660 KB |
Output is correct |
24 |
Correct |
4 ms |
13660 KB |
Output is correct |
25 |
Correct |
4 ms |
13660 KB |
Output is correct |
26 |
Correct |
4 ms |
13660 KB |
Output is correct |
27 |
Correct |
4 ms |
13660 KB |
Output is correct |
28 |
Correct |
4 ms |
13660 KB |
Output is correct |
29 |
Correct |
4 ms |
13576 KB |
Output is correct |
30 |
Correct |
4 ms |
13660 KB |
Output is correct |
31 |
Correct |
4 ms |
13660 KB |
Output is correct |
32 |
Correct |
4 ms |
13508 KB |
Output is correct |
33 |
Correct |
4 ms |
13912 KB |
Output is correct |
34 |
Correct |
7 ms |
13660 KB |
Output is correct |
35 |
Correct |
6 ms |
13660 KB |
Output is correct |
36 |
Correct |
7 ms |
13732 KB |
Output is correct |
37 |
Correct |
7 ms |
13692 KB |
Output is correct |
38 |
Correct |
6 ms |
13656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
13660 KB |
Output is correct |
2 |
Correct |
3 ms |
13660 KB |
Output is correct |
3 |
Correct |
3 ms |
13660 KB |
Output is correct |
4 |
Correct |
3 ms |
13656 KB |
Output is correct |
5 |
Correct |
3 ms |
13656 KB |
Output is correct |
6 |
Correct |
4 ms |
13660 KB |
Output is correct |
7 |
Correct |
4 ms |
13660 KB |
Output is correct |
8 |
Correct |
4 ms |
13660 KB |
Output is correct |
9 |
Correct |
4 ms |
13660 KB |
Output is correct |
10 |
Correct |
4 ms |
13500 KB |
Output is correct |
11 |
Correct |
4 ms |
13660 KB |
Output is correct |
12 |
Correct |
3 ms |
13660 KB |
Output is correct |
13 |
Correct |
3 ms |
13660 KB |
Output is correct |
14 |
Correct |
4 ms |
13660 KB |
Output is correct |
15 |
Correct |
4 ms |
13660 KB |
Output is correct |
16 |
Correct |
3 ms |
13656 KB |
Output is correct |
17 |
Correct |
4 ms |
13660 KB |
Output is correct |
18 |
Correct |
3 ms |
13656 KB |
Output is correct |
19 |
Correct |
170 ms |
19540 KB |
Output is correct |
20 |
Correct |
170 ms |
19536 KB |
Output is correct |
21 |
Correct |
176 ms |
19484 KB |
Output is correct |
22 |
Correct |
130 ms |
19536 KB |
Output is correct |
23 |
Correct |
60 ms |
19804 KB |
Output is correct |
24 |
Correct |
41 ms |
19548 KB |
Output is correct |
25 |
Execution timed out |
3051 ms |
23120 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
13660 KB |
Output is correct |
2 |
Correct |
3 ms |
13660 KB |
Output is correct |
3 |
Correct |
3 ms |
13660 KB |
Output is correct |
4 |
Correct |
3 ms |
13656 KB |
Output is correct |
5 |
Correct |
3 ms |
13656 KB |
Output is correct |
6 |
Correct |
4 ms |
13660 KB |
Output is correct |
7 |
Correct |
4 ms |
13660 KB |
Output is correct |
8 |
Correct |
4 ms |
13660 KB |
Output is correct |
9 |
Correct |
4 ms |
13660 KB |
Output is correct |
10 |
Correct |
4 ms |
13500 KB |
Output is correct |
11 |
Correct |
4 ms |
13660 KB |
Output is correct |
12 |
Correct |
3 ms |
13660 KB |
Output is correct |
13 |
Correct |
3 ms |
13660 KB |
Output is correct |
14 |
Correct |
4 ms |
13660 KB |
Output is correct |
15 |
Correct |
4 ms |
13660 KB |
Output is correct |
16 |
Correct |
3 ms |
13656 KB |
Output is correct |
17 |
Correct |
4 ms |
13660 KB |
Output is correct |
18 |
Correct |
3 ms |
13656 KB |
Output is correct |
19 |
Correct |
5 ms |
13660 KB |
Output is correct |
20 |
Correct |
4 ms |
13656 KB |
Output is correct |
21 |
Correct |
4 ms |
13564 KB |
Output is correct |
22 |
Correct |
4 ms |
13660 KB |
Output is correct |
23 |
Correct |
4 ms |
13660 KB |
Output is correct |
24 |
Correct |
4 ms |
13660 KB |
Output is correct |
25 |
Correct |
4 ms |
13660 KB |
Output is correct |
26 |
Correct |
4 ms |
13660 KB |
Output is correct |
27 |
Correct |
4 ms |
13660 KB |
Output is correct |
28 |
Correct |
4 ms |
13660 KB |
Output is correct |
29 |
Correct |
4 ms |
13576 KB |
Output is correct |
30 |
Correct |
4 ms |
13660 KB |
Output is correct |
31 |
Correct |
4 ms |
13660 KB |
Output is correct |
32 |
Correct |
4 ms |
13508 KB |
Output is correct |
33 |
Correct |
4 ms |
13912 KB |
Output is correct |
34 |
Correct |
7 ms |
13660 KB |
Output is correct |
35 |
Correct |
6 ms |
13660 KB |
Output is correct |
36 |
Correct |
7 ms |
13732 KB |
Output is correct |
37 |
Correct |
7 ms |
13692 KB |
Output is correct |
38 |
Correct |
6 ms |
13656 KB |
Output is correct |
39 |
Correct |
170 ms |
19540 KB |
Output is correct |
40 |
Correct |
170 ms |
19536 KB |
Output is correct |
41 |
Correct |
176 ms |
19484 KB |
Output is correct |
42 |
Correct |
130 ms |
19536 KB |
Output is correct |
43 |
Correct |
60 ms |
19804 KB |
Output is correct |
44 |
Correct |
41 ms |
19548 KB |
Output is correct |
45 |
Execution timed out |
3051 ms |
23120 KB |
Time limit exceeded |
46 |
Halted |
0 ms |
0 KB |
- |