#include <bits/stdc++.h>
using namespace std;
const int MX=2e5+5;
int N;
vector<int> adj[MX];
bool used[MX];
int sz[MX];
int f[MX];
vector<pair<int,int>> mxs[MX];
int getSize(int v, int p) {
sz[v]=1;
for(auto u:adj[v]) {
if(u==p || used[u]) continue;
sz[v]+=getSize(u,v);
}
return sz[v];
}
int getCen(int v, int p, int s) {
for(auto u:adj[v]) {
if(u==p || used[u]) continue;
if(2*sz[u]>s) return getCen(u,v,s);
}
return v;
}
int head=0,s=0;
int ans[MX];
void dfs(int v, int p, int dep) {
f[sz[v]]=max(f[sz[v]],dep);
int i=min(sz[v],s-sz[head]);
ans[2*i]=max(ans[2*i],dep+1);
for(auto u:adj[v]) {
if(u==p || used[u]) continue;
dfs(u,v,dep+1);
}
}
void cdc(int v) {
s=getSize(v,v);
int cen=getCen(v,v,s);
used[cen]=true;
getSize(cen,cen);
for(auto u:adj[cen]) {
if(!used[u]) {
head=u;
dfs(u,cen,1);
for(int i=1;i<=sz[u];i++) {
mxs[i].push_back({f[i],u});
sort(mxs[i].rbegin(),mxs[i].rend());
while(mxs[i].size()>2) mxs[i].pop_back();
f[i]=0;
}
}
}
vector<pair<int,int>> vv;
for(int i=s;i>=1;i--) {
vector<pair<int,int>> nv;
for(auto [fi,u]:mxs[i]) {
vv.push_back({fi,u});
}
sort(vv.rbegin(),vv.rend());
for(auto [fi,u]:vv) {
if(nv.empty()) {
nv.push_back({fi,u});
continue;
}
if(nv.size()==1) {
if(nv.back().second!=u) nv.push_back({fi,u});
continue;
}
break;
}
swap(vv,nv);
if(vv.size()>1) {
ans[2*i]=max(ans[2*i],vv[0].first+vv[1].first+1);
}
}
for(int i=1;i<=sz[cen];i++) {
mxs[i].clear();
}
for(auto u:adj[cen]) {
if(!used[u]) {
cdc(u);
}
}
}
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin>>N;
for(int i=1;i<N;i++) {
int u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
cdc(1);
ans[N+1]=1;
for(int i=N;i>=1;i--)
ans[i]=max(ans[i],ans[i+1]);
for(int i=1;i<=N;i++) {
if(i&1) {
cout<<1<<'\n';
} else {
cout<<ans[i]<<'\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12376 KB |
Output is correct |
2 |
Correct |
3 ms |
12376 KB |
Output is correct |
3 |
Correct |
3 ms |
12068 KB |
Output is correct |
4 |
Correct |
3 ms |
12124 KB |
Output is correct |
5 |
Correct |
3 ms |
12124 KB |
Output is correct |
6 |
Correct |
3 ms |
12120 KB |
Output is correct |
7 |
Correct |
3 ms |
12124 KB |
Output is correct |
8 |
Correct |
3 ms |
12124 KB |
Output is correct |
9 |
Correct |
4 ms |
12124 KB |
Output is correct |
10 |
Correct |
3 ms |
12184 KB |
Output is correct |
11 |
Correct |
3 ms |
12124 KB |
Output is correct |
12 |
Correct |
3 ms |
12124 KB |
Output is correct |
13 |
Correct |
3 ms |
12124 KB |
Output is correct |
14 |
Correct |
3 ms |
12124 KB |
Output is correct |
15 |
Correct |
3 ms |
12120 KB |
Output is correct |
16 |
Correct |
3 ms |
12124 KB |
Output is correct |
17 |
Correct |
3 ms |
12124 KB |
Output is correct |
18 |
Correct |
3 ms |
12124 KB |
Output is correct |
19 |
Correct |
3 ms |
12124 KB |
Output is correct |
20 |
Correct |
3 ms |
12376 KB |
Output is correct |
21 |
Correct |
3 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12376 KB |
Output is correct |
2 |
Correct |
3 ms |
12376 KB |
Output is correct |
3 |
Correct |
3 ms |
12068 KB |
Output is correct |
4 |
Correct |
3 ms |
12124 KB |
Output is correct |
5 |
Correct |
3 ms |
12124 KB |
Output is correct |
6 |
Correct |
3 ms |
12120 KB |
Output is correct |
7 |
Correct |
3 ms |
12124 KB |
Output is correct |
8 |
Correct |
3 ms |
12124 KB |
Output is correct |
9 |
Correct |
4 ms |
12124 KB |
Output is correct |
10 |
Correct |
3 ms |
12184 KB |
Output is correct |
11 |
Correct |
3 ms |
12124 KB |
Output is correct |
12 |
Correct |
3 ms |
12124 KB |
Output is correct |
13 |
Correct |
3 ms |
12124 KB |
Output is correct |
14 |
Correct |
3 ms |
12124 KB |
Output is correct |
15 |
Correct |
3 ms |
12120 KB |
Output is correct |
16 |
Correct |
3 ms |
12124 KB |
Output is correct |
17 |
Correct |
3 ms |
12124 KB |
Output is correct |
18 |
Correct |
3 ms |
12124 KB |
Output is correct |
19 |
Correct |
3 ms |
12124 KB |
Output is correct |
20 |
Correct |
3 ms |
12376 KB |
Output is correct |
21 |
Correct |
3 ms |
12124 KB |
Output is correct |
22 |
Correct |
8 ms |
12944 KB |
Output is correct |
23 |
Correct |
7 ms |
12380 KB |
Output is correct |
24 |
Correct |
6 ms |
12380 KB |
Output is correct |
25 |
Correct |
7 ms |
12376 KB |
Output is correct |
26 |
Correct |
6 ms |
12380 KB |
Output is correct |
27 |
Correct |
6 ms |
12380 KB |
Output is correct |
28 |
Correct |
6 ms |
12380 KB |
Output is correct |
29 |
Correct |
6 ms |
12380 KB |
Output is correct |
30 |
Correct |
7 ms |
12380 KB |
Output is correct |
31 |
Correct |
7 ms |
12380 KB |
Output is correct |
32 |
Correct |
8 ms |
12380 KB |
Output is correct |
33 |
Correct |
8 ms |
12592 KB |
Output is correct |
34 |
Correct |
4 ms |
12376 KB |
Output is correct |
35 |
Correct |
4 ms |
12380 KB |
Output is correct |
36 |
Correct |
6 ms |
12380 KB |
Output is correct |
37 |
Correct |
5 ms |
12380 KB |
Output is correct |
38 |
Correct |
6 ms |
12380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12376 KB |
Output is correct |
2 |
Correct |
3 ms |
12376 KB |
Output is correct |
3 |
Correct |
3 ms |
12068 KB |
Output is correct |
4 |
Correct |
3 ms |
12124 KB |
Output is correct |
5 |
Correct |
3 ms |
12124 KB |
Output is correct |
6 |
Correct |
3 ms |
12120 KB |
Output is correct |
7 |
Correct |
3 ms |
12124 KB |
Output is correct |
8 |
Correct |
3 ms |
12124 KB |
Output is correct |
9 |
Correct |
4 ms |
12124 KB |
Output is correct |
10 |
Correct |
3 ms |
12184 KB |
Output is correct |
11 |
Correct |
3 ms |
12124 KB |
Output is correct |
12 |
Correct |
3 ms |
12124 KB |
Output is correct |
13 |
Correct |
3 ms |
12124 KB |
Output is correct |
14 |
Correct |
3 ms |
12124 KB |
Output is correct |
15 |
Correct |
3 ms |
12120 KB |
Output is correct |
16 |
Correct |
3 ms |
12124 KB |
Output is correct |
17 |
Correct |
3 ms |
12124 KB |
Output is correct |
18 |
Correct |
3 ms |
12124 KB |
Output is correct |
19 |
Correct |
3 ms |
12124 KB |
Output is correct |
20 |
Correct |
3 ms |
12376 KB |
Output is correct |
21 |
Correct |
3 ms |
12124 KB |
Output is correct |
22 |
Correct |
8 ms |
12944 KB |
Output is correct |
23 |
Correct |
7 ms |
12380 KB |
Output is correct |
24 |
Correct |
6 ms |
12380 KB |
Output is correct |
25 |
Correct |
7 ms |
12376 KB |
Output is correct |
26 |
Correct |
6 ms |
12380 KB |
Output is correct |
27 |
Correct |
6 ms |
12380 KB |
Output is correct |
28 |
Correct |
6 ms |
12380 KB |
Output is correct |
29 |
Correct |
6 ms |
12380 KB |
Output is correct |
30 |
Correct |
7 ms |
12380 KB |
Output is correct |
31 |
Correct |
7 ms |
12380 KB |
Output is correct |
32 |
Correct |
8 ms |
12380 KB |
Output is correct |
33 |
Correct |
8 ms |
12592 KB |
Output is correct |
34 |
Correct |
4 ms |
12376 KB |
Output is correct |
35 |
Correct |
4 ms |
12380 KB |
Output is correct |
36 |
Correct |
6 ms |
12380 KB |
Output is correct |
37 |
Correct |
5 ms |
12380 KB |
Output is correct |
38 |
Correct |
6 ms |
12380 KB |
Output is correct |
39 |
Correct |
331 ms |
22396 KB |
Output is correct |
40 |
Correct |
364 ms |
24924 KB |
Output is correct |
41 |
Correct |
313 ms |
24656 KB |
Output is correct |
42 |
Correct |
299 ms |
24656 KB |
Output is correct |
43 |
Correct |
319 ms |
24916 KB |
Output is correct |
44 |
Correct |
321 ms |
24688 KB |
Output is correct |
45 |
Correct |
575 ms |
28640 KB |
Output is correct |
46 |
Correct |
477 ms |
32084 KB |
Output is correct |
47 |
Correct |
98 ms |
21968 KB |
Output is correct |
48 |
Correct |
77 ms |
22216 KB |
Output is correct |
49 |
Correct |
309 ms |
25380 KB |
Output is correct |
50 |
Correct |
106 ms |
26172 KB |
Output is correct |
51 |
Correct |
273 ms |
31232 KB |
Output is correct |