#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
const int N=2e5+99;
int n,t,prt,a[N],b[N],sz[N],mark[N],ans[N];
vector<int> g[N];
void dfs1(int u,int p,int s,int ¢){
sz[u]=1;
for(auto v : g[u]){
if(v==p || mark[v]) continue ;
dfs1(v,u,s,cent);
sz[u]+=sz[v];
}
if(sz[u]>=s && (cent==0 || sz[u]<sz[cent])){
cent=u;
}
}
void dfs2(int u,int p,int h){
maxm(a[sz[u]],h);
for(auto v : g[u]){
if(v==p || mark[v]) continue ;
dfs2(v,u,h+1);
}
}
void solve(int rt,int m=n){
if(m==1) return ;
int cent=0;
dfs1(rt,rt,(m+1)/2,cent);
dfs1(cent,cent,0,prt);
mark[cent]=1;
f(i,1,sz[cent]+1) b[i]=-N;
for(auto v : g[cent]){
if(mark[v]) continue ;
f(i,1,sz[v]+1) a[i]=-N;
dfs2(v,v,1);
f_(i,sz[v]-1,1) maxm(a[i],a[i+1]);
//cout<<v<<" : "<<endl;
//dbga(a,1,sz[v]+1);
f(i,1,sz[v]+1){
maxm(ans[i],a[i]+b[i]+1);
maxm(b[i],a[i]);
//cout<<i<<" -> "<<sz[v]<<endl;
if(i<=m-sz[v]){
maxm(ans[i],b[i]+1);
}
}
}
for(auto v : g[cent]){
if(mark[v]) continue ;
solve(v,sz[v]);
}
}
main(){
ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin>>n;
f(i,1,n){
int u,v;
cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
}
solve(1);
f(i,1,n+1){
if(i&1) cout<<1<<'\n';
else{
cout<<max(1,ans[i/2])<<'\n';
}
}
}
Compilation message
meetings2.cpp:74:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
74 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
2 ms |
5000 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
2 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
5024 KB |
Output is correct |
21 |
Correct |
2 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
2 ms |
5000 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
2 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
5024 KB |
Output is correct |
21 |
Correct |
2 ms |
4940 KB |
Output is correct |
22 |
Correct |
6 ms |
5168 KB |
Output is correct |
23 |
Correct |
5 ms |
5164 KB |
Output is correct |
24 |
Correct |
6 ms |
5172 KB |
Output is correct |
25 |
Correct |
6 ms |
5168 KB |
Output is correct |
26 |
Correct |
6 ms |
5168 KB |
Output is correct |
27 |
Correct |
5 ms |
5196 KB |
Output is correct |
28 |
Correct |
6 ms |
5196 KB |
Output is correct |
29 |
Correct |
6 ms |
5196 KB |
Output is correct |
30 |
Correct |
6 ms |
5196 KB |
Output is correct |
31 |
Correct |
6 ms |
5196 KB |
Output is correct |
32 |
Correct |
9 ms |
5324 KB |
Output is correct |
33 |
Correct |
7 ms |
5452 KB |
Output is correct |
34 |
Correct |
6 ms |
5228 KB |
Output is correct |
35 |
Correct |
6 ms |
5196 KB |
Output is correct |
36 |
Correct |
6 ms |
5196 KB |
Output is correct |
37 |
Correct |
5 ms |
5196 KB |
Output is correct |
38 |
Correct |
6 ms |
5324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
2 ms |
5000 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
2 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
5024 KB |
Output is correct |
21 |
Correct |
2 ms |
4940 KB |
Output is correct |
22 |
Correct |
6 ms |
5168 KB |
Output is correct |
23 |
Correct |
5 ms |
5164 KB |
Output is correct |
24 |
Correct |
6 ms |
5172 KB |
Output is correct |
25 |
Correct |
6 ms |
5168 KB |
Output is correct |
26 |
Correct |
6 ms |
5168 KB |
Output is correct |
27 |
Correct |
5 ms |
5196 KB |
Output is correct |
28 |
Correct |
6 ms |
5196 KB |
Output is correct |
29 |
Correct |
6 ms |
5196 KB |
Output is correct |
30 |
Correct |
6 ms |
5196 KB |
Output is correct |
31 |
Correct |
6 ms |
5196 KB |
Output is correct |
32 |
Correct |
9 ms |
5324 KB |
Output is correct |
33 |
Correct |
7 ms |
5452 KB |
Output is correct |
34 |
Correct |
6 ms |
5228 KB |
Output is correct |
35 |
Correct |
6 ms |
5196 KB |
Output is correct |
36 |
Correct |
6 ms |
5196 KB |
Output is correct |
37 |
Correct |
5 ms |
5196 KB |
Output is correct |
38 |
Correct |
6 ms |
5324 KB |
Output is correct |
39 |
Correct |
421 ms |
17208 KB |
Output is correct |
40 |
Correct |
399 ms |
17004 KB |
Output is correct |
41 |
Correct |
389 ms |
17260 KB |
Output is correct |
42 |
Correct |
397 ms |
17348 KB |
Output is correct |
43 |
Correct |
377 ms |
17348 KB |
Output is correct |
44 |
Correct |
399 ms |
17348 KB |
Output is correct |
45 |
Correct |
625 ms |
23320 KB |
Output is correct |
46 |
Correct |
477 ms |
28204 KB |
Output is correct |
47 |
Correct |
185 ms |
17020 KB |
Output is correct |
48 |
Correct |
89 ms |
16384 KB |
Output is correct |
49 |
Correct |
315 ms |
18124 KB |
Output is correct |
50 |
Correct |
124 ms |
17636 KB |
Output is correct |
51 |
Correct |
279 ms |
26944 KB |
Output is correct |