This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MX=2e5+5;
int N;
vector<int> adj[MX];
int sz[MX], ans[MX];
void dfs(int v, int p, int head, int dep) {
sz[v]=1;
for(auto u:adj[v]) {
if(u==p) continue;
dfs(u,v,head,dep+1);
sz[v]+=sz[u];
}
}
void dfs2(int v, int p, int head, int dep) {
for(auto u:adj[v]) {
if(u==p) continue;
dfs2(u,v,head,dep+1);
}
int k=min(sz[v],N-sz[head]);
ans[2*k]=max(ans[2*k],dep+1);
}
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);
}
for(int r=1;r<=N;r++) {
for(auto u:adj[r]) {
dfs(u,r,u,1);
dfs2(u,r,u,1);
}
}
for(int i=2*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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |