#include<bits/stdc++.h>
using namespace std;
const int nax = 4002;
vector<int>g[nax];
int n;
int ans[nax * 2];
int sub[nax];
int dfs0(int v, int p = 0) {
sub[v] = 1;
for(int u: g[v]) if(u!=p) {
sub[v] += dfs0(u, v);
}
return sub[v];
}
void dfs(int v, int p = 0, int d = 1, int ot = n) {
if(p) ans[min(sub[v], ot) * 2] = max(ans[min(sub[v], ot) * 2], d);
for(int u : g[v]) if(u!=p) {
int new_ot = ot;
if(p==0) {
new_ot = ot - sub[u];
}
dfs(u, v, d+1, new_ot);
}
}
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) {
dfs0(r);
dfs(r);
}
int mx = 0;
for(int i=2*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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |