# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
551232 |
2022-04-20T06:10:34 Z |
Koosha_mv |
Race (IOI11_race) |
C++14 |
|
424 ms |
52444 KB |
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#include "race.h"
const int N=1e6+99;
int n,k,cent,ans=N,sz[N],vis[N],res[N];
int a[N][2],b[N];
vector<int> alh;
vector<pair<int,int>> vec,g[N];
void dfs1(int u,int p,int n){
sz[u]=1;
for(auto v : g[u]){
if(p==v.F || vis[v.F]) continue ;
dfs1(v.F,u,n);
sz[u]+=sz[v.F];
}
if(2*sz[u]>=n && cent==-1) cent=u;
}
void dfs2(int u,int p,int h1,int h2){
sz[u]=1;
if(h2<=k){
minm(ans,h1+res[k-h2]);
alh.pb(h2);
vec.pb({h2,h1});
}
else h2=k+1;
for(auto v : g[u]){
if(p==v.F || vis[v.F]) continue ;
dfs2(v.F,u,h1+1,h2+v.S);
sz[u]+=sz[v.F];
}
}
void solve(int rt,int n){
cent=-1;
dfs1(rt,rt,n);
if(cent==-1) assert(0);
res[0]=0;
alh.clear();
for(auto v : g[cent]){
if(vis[v.F]) continue ;
vec.clear();
dfs2(v.F,cent,1,v.S);
for(auto p : vec) minm(res[p.F],p.S);
}
for(auto x : alh) res[x]=N;
vis[cent]=1;
for(auto v : g[cent]){
if(vis[v.F]) continue ;
solve(v.F,sz[v.F]);
}
}
int best_path(int _n, int _k,int H[][2],int L[]){
fill(res,res+N,N);
n=_n,k=_k;
f(i,0,n-1){
int u=H[i][0],v=H[i][1],w=L[i];
g[u].pb({v,w});
g[v].pb({u,w});
}
solve(1,n);
if(ans==N) return -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
27664 KB |
Output is correct |
2 |
Correct |
14 ms |
27660 KB |
Output is correct |
3 |
Correct |
13 ms |
27732 KB |
Output is correct |
4 |
Correct |
14 ms |
27732 KB |
Output is correct |
5 |
Correct |
15 ms |
27732 KB |
Output is correct |
6 |
Correct |
15 ms |
27744 KB |
Output is correct |
7 |
Correct |
17 ms |
27628 KB |
Output is correct |
8 |
Correct |
16 ms |
27644 KB |
Output is correct |
9 |
Correct |
14 ms |
27732 KB |
Output is correct |
10 |
Correct |
16 ms |
27732 KB |
Output is correct |
11 |
Correct |
15 ms |
27720 KB |
Output is correct |
12 |
Correct |
18 ms |
27712 KB |
Output is correct |
13 |
Correct |
14 ms |
27732 KB |
Output is correct |
14 |
Correct |
15 ms |
27688 KB |
Output is correct |
15 |
Correct |
14 ms |
27728 KB |
Output is correct |
16 |
Correct |
14 ms |
27724 KB |
Output is correct |
17 |
Correct |
13 ms |
27752 KB |
Output is correct |
18 |
Correct |
14 ms |
27744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
27664 KB |
Output is correct |
2 |
Correct |
14 ms |
27660 KB |
Output is correct |
3 |
Correct |
13 ms |
27732 KB |
Output is correct |
4 |
Correct |
14 ms |
27732 KB |
Output is correct |
5 |
Correct |
15 ms |
27732 KB |
Output is correct |
6 |
Correct |
15 ms |
27744 KB |
Output is correct |
7 |
Correct |
17 ms |
27628 KB |
Output is correct |
8 |
Correct |
16 ms |
27644 KB |
Output is correct |
9 |
Correct |
14 ms |
27732 KB |
Output is correct |
10 |
Correct |
16 ms |
27732 KB |
Output is correct |
11 |
Correct |
15 ms |
27720 KB |
Output is correct |
12 |
Correct |
18 ms |
27712 KB |
Output is correct |
13 |
Correct |
14 ms |
27732 KB |
Output is correct |
14 |
Correct |
15 ms |
27688 KB |
Output is correct |
15 |
Correct |
14 ms |
27728 KB |
Output is correct |
16 |
Correct |
14 ms |
27724 KB |
Output is correct |
17 |
Correct |
13 ms |
27752 KB |
Output is correct |
18 |
Correct |
14 ms |
27744 KB |
Output is correct |
19 |
Correct |
13 ms |
27628 KB |
Output is correct |
20 |
Correct |
13 ms |
27732 KB |
Output is correct |
21 |
Correct |
14 ms |
27732 KB |
Output is correct |
22 |
Correct |
14 ms |
27732 KB |
Output is correct |
23 |
Correct |
16 ms |
27732 KB |
Output is correct |
24 |
Correct |
15 ms |
27732 KB |
Output is correct |
25 |
Correct |
15 ms |
27784 KB |
Output is correct |
26 |
Correct |
15 ms |
27732 KB |
Output is correct |
27 |
Correct |
15 ms |
27800 KB |
Output is correct |
28 |
Correct |
15 ms |
27800 KB |
Output is correct |
29 |
Correct |
14 ms |
27724 KB |
Output is correct |
30 |
Correct |
14 ms |
27692 KB |
Output is correct |
31 |
Correct |
16 ms |
27704 KB |
Output is correct |
32 |
Correct |
15 ms |
27792 KB |
Output is correct |
33 |
Correct |
15 ms |
27796 KB |
Output is correct |
34 |
Correct |
19 ms |
27804 KB |
Output is correct |
35 |
Correct |
17 ms |
27780 KB |
Output is correct |
36 |
Correct |
15 ms |
27812 KB |
Output is correct |
37 |
Correct |
15 ms |
27816 KB |
Output is correct |
38 |
Correct |
15 ms |
27696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
27664 KB |
Output is correct |
2 |
Correct |
14 ms |
27660 KB |
Output is correct |
3 |
Correct |
13 ms |
27732 KB |
Output is correct |
4 |
Correct |
14 ms |
27732 KB |
Output is correct |
5 |
Correct |
15 ms |
27732 KB |
Output is correct |
6 |
Correct |
15 ms |
27744 KB |
Output is correct |
7 |
Correct |
17 ms |
27628 KB |
Output is correct |
8 |
Correct |
16 ms |
27644 KB |
Output is correct |
9 |
Correct |
14 ms |
27732 KB |
Output is correct |
10 |
Correct |
16 ms |
27732 KB |
Output is correct |
11 |
Correct |
15 ms |
27720 KB |
Output is correct |
12 |
Correct |
18 ms |
27712 KB |
Output is correct |
13 |
Correct |
14 ms |
27732 KB |
Output is correct |
14 |
Correct |
15 ms |
27688 KB |
Output is correct |
15 |
Correct |
14 ms |
27728 KB |
Output is correct |
16 |
Correct |
14 ms |
27724 KB |
Output is correct |
17 |
Correct |
13 ms |
27752 KB |
Output is correct |
18 |
Correct |
14 ms |
27744 KB |
Output is correct |
19 |
Correct |
145 ms |
33480 KB |
Output is correct |
20 |
Correct |
155 ms |
33408 KB |
Output is correct |
21 |
Correct |
139 ms |
33860 KB |
Output is correct |
22 |
Correct |
114 ms |
34044 KB |
Output is correct |
23 |
Correct |
104 ms |
33600 KB |
Output is correct |
24 |
Correct |
70 ms |
33472 KB |
Output is correct |
25 |
Correct |
129 ms |
39924 KB |
Output is correct |
26 |
Correct |
101 ms |
41548 KB |
Output is correct |
27 |
Correct |
176 ms |
39216 KB |
Output is correct |
28 |
Correct |
364 ms |
52444 KB |
Output is correct |
29 |
Correct |
321 ms |
47300 KB |
Output is correct |
30 |
Correct |
199 ms |
39172 KB |
Output is correct |
31 |
Correct |
171 ms |
39244 KB |
Output is correct |
32 |
Correct |
252 ms |
39116 KB |
Output is correct |
33 |
Correct |
221 ms |
37968 KB |
Output is correct |
34 |
Correct |
258 ms |
38012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
27664 KB |
Output is correct |
2 |
Correct |
14 ms |
27660 KB |
Output is correct |
3 |
Correct |
13 ms |
27732 KB |
Output is correct |
4 |
Correct |
14 ms |
27732 KB |
Output is correct |
5 |
Correct |
15 ms |
27732 KB |
Output is correct |
6 |
Correct |
15 ms |
27744 KB |
Output is correct |
7 |
Correct |
17 ms |
27628 KB |
Output is correct |
8 |
Correct |
16 ms |
27644 KB |
Output is correct |
9 |
Correct |
14 ms |
27732 KB |
Output is correct |
10 |
Correct |
16 ms |
27732 KB |
Output is correct |
11 |
Correct |
15 ms |
27720 KB |
Output is correct |
12 |
Correct |
18 ms |
27712 KB |
Output is correct |
13 |
Correct |
14 ms |
27732 KB |
Output is correct |
14 |
Correct |
15 ms |
27688 KB |
Output is correct |
15 |
Correct |
14 ms |
27728 KB |
Output is correct |
16 |
Correct |
14 ms |
27724 KB |
Output is correct |
17 |
Correct |
13 ms |
27752 KB |
Output is correct |
18 |
Correct |
14 ms |
27744 KB |
Output is correct |
19 |
Correct |
13 ms |
27628 KB |
Output is correct |
20 |
Correct |
13 ms |
27732 KB |
Output is correct |
21 |
Correct |
14 ms |
27732 KB |
Output is correct |
22 |
Correct |
14 ms |
27732 KB |
Output is correct |
23 |
Correct |
16 ms |
27732 KB |
Output is correct |
24 |
Correct |
15 ms |
27732 KB |
Output is correct |
25 |
Correct |
15 ms |
27784 KB |
Output is correct |
26 |
Correct |
15 ms |
27732 KB |
Output is correct |
27 |
Correct |
15 ms |
27800 KB |
Output is correct |
28 |
Correct |
15 ms |
27800 KB |
Output is correct |
29 |
Correct |
14 ms |
27724 KB |
Output is correct |
30 |
Correct |
14 ms |
27692 KB |
Output is correct |
31 |
Correct |
16 ms |
27704 KB |
Output is correct |
32 |
Correct |
15 ms |
27792 KB |
Output is correct |
33 |
Correct |
15 ms |
27796 KB |
Output is correct |
34 |
Correct |
19 ms |
27804 KB |
Output is correct |
35 |
Correct |
17 ms |
27780 KB |
Output is correct |
36 |
Correct |
15 ms |
27812 KB |
Output is correct |
37 |
Correct |
15 ms |
27816 KB |
Output is correct |
38 |
Correct |
15 ms |
27696 KB |
Output is correct |
39 |
Correct |
145 ms |
33480 KB |
Output is correct |
40 |
Correct |
155 ms |
33408 KB |
Output is correct |
41 |
Correct |
139 ms |
33860 KB |
Output is correct |
42 |
Correct |
114 ms |
34044 KB |
Output is correct |
43 |
Correct |
104 ms |
33600 KB |
Output is correct |
44 |
Correct |
70 ms |
33472 KB |
Output is correct |
45 |
Correct |
129 ms |
39924 KB |
Output is correct |
46 |
Correct |
101 ms |
41548 KB |
Output is correct |
47 |
Correct |
176 ms |
39216 KB |
Output is correct |
48 |
Correct |
364 ms |
52444 KB |
Output is correct |
49 |
Correct |
321 ms |
47300 KB |
Output is correct |
50 |
Correct |
199 ms |
39172 KB |
Output is correct |
51 |
Correct |
171 ms |
39244 KB |
Output is correct |
52 |
Correct |
252 ms |
39116 KB |
Output is correct |
53 |
Correct |
221 ms |
37968 KB |
Output is correct |
54 |
Correct |
258 ms |
38012 KB |
Output is correct |
55 |
Correct |
21 ms |
28384 KB |
Output is correct |
56 |
Correct |
22 ms |
28372 KB |
Output is correct |
57 |
Correct |
92 ms |
34392 KB |
Output is correct |
58 |
Correct |
46 ms |
34604 KB |
Output is correct |
59 |
Correct |
99 ms |
41536 KB |
Output is correct |
60 |
Correct |
368 ms |
49080 KB |
Output is correct |
61 |
Correct |
173 ms |
39380 KB |
Output is correct |
62 |
Correct |
186 ms |
40004 KB |
Output is correct |
63 |
Correct |
254 ms |
40084 KB |
Output is correct |
64 |
Correct |
403 ms |
40548 KB |
Output is correct |
65 |
Correct |
309 ms |
39104 KB |
Output is correct |
66 |
Correct |
424 ms |
51096 KB |
Output is correct |
67 |
Correct |
140 ms |
41144 KB |
Output is correct |
68 |
Correct |
228 ms |
39816 KB |
Output is correct |
69 |
Correct |
273 ms |
39860 KB |
Output is correct |
70 |
Correct |
218 ms |
39256 KB |
Output is correct |