#include<bits/stdc++.h>
using namespace std;
const int nax = 4002;
vector<int>g[nax];
int n;
int ans[nax];
int sub[nax][nax];
int dist[nax][nax];
int dfs(int v, int r, int p = 0) {
sub[r][v] = 1;
if(p) dist[r][v] = dist[r][p] + 1;
for(int u: g[v]) if(u!=p) {
sub[r][v] += dfs(u, r, v);
}
return sub[r][v];
}
void PlayGround() {
cin>>n;
for(int i=0; i<n-1; ++i) {
int u, v;
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
for(int r=1; r<=n; ++r) {
dfs(r, r);
}
for(int i=1; i<=n; ++i) {
for(int j=i+1; j<=n; ++j) {
int sz = min(sub[i][j], sub[j][i]) * 2;
ans[sz] = max(ans[sz], dist[i][j]+1);
}
}
int mx = 0;
ans[n] = 1;
for(int i=n; i>0; --i) {
if(i&1) ans[i] = 1;
else {
mx = max(mx, ans[i]);
ans[i] = mx;
}
}
for(int i=1; i<=n; ++i) {
cout<<ans[i]<<'\n';
}
// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
PlayGround();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |