#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
#define pb emplace_back
#define f first
#define s second
#define mp make_pair
#define SZ(x) (ll)x.size()
#define ALL(x) x.begin(),x.end()
#define lb lower_bound
#define ub upper_bound
const ll MAXN=5010;
ll N,a,b,c,d,Q;
vi V[MAXN];
ll ans;
ll p[MAXN];
ll sub[MAXN];
ll small[MAXN];
ll A[MAXN];
ll out[MAXN];
ll dfs(ll x,ll pa){
sub[x]=1;
p[x]=pa;
for(auto v:V[x])if(v!=pa)sub[x]+=dfs(v,x);
return sub[x];
}
void dfs2(ll x,ll d,ll pa){
if(A[x])ans=max(ans,d);
for(auto v:V[x])if(v!=pa)dfs2(v,d+1,x);
}
int main(){
cin>>N;
for(ll i=1;i<N;++i){
cin>>a>>b;
V[a].pb(b);
V[b].pb(a);
}
dfs(1,-1);
for(ll i=1;i<=N;++i){
b=N-sub[i];
for(auto j:V[i])if(j!=p[i]){
b=max(b,sub[j]);
}
small[i]=N-b; // everything except biggest subtree
}
// for(ll i=1;i<=N;++i)cerr<<small[i]<<' ';cerr<<'\n';
vpi nodes;
for(ll i=1;i<=N;++i)nodes.pb(small[i],i);
sort(ALL(nodes));
for(ll i=(N/2)*2; i>=2;i-=2){
while(SZ(nodes)&&nodes.back().f>=i/2){
pi t=nodes.back();nodes.pop_back();
A[t.s]=1;
// cerr<<"Adding "<<t.s<<'\n';
dfs2(t.s,1,-1);
}
out[i]=ans;
}
for(int i=1;i<=N;++i){
if(i%2)cout<<1<<'\n';
else cout<<out[i]<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
432 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
420 KB |
Output is correct |
15 |
Correct |
1 ms |
420 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
420 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
432 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
420 KB |
Output is correct |
15 |
Correct |
1 ms |
420 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
420 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
253 ms |
880 KB |
Output is correct |
23 |
Correct |
245 ms |
896 KB |
Output is correct |
24 |
Correct |
235 ms |
892 KB |
Output is correct |
25 |
Correct |
236 ms |
844 KB |
Output is correct |
26 |
Correct |
260 ms |
892 KB |
Output is correct |
27 |
Correct |
236 ms |
844 KB |
Output is correct |
28 |
Correct |
244 ms |
868 KB |
Output is correct |
29 |
Correct |
248 ms |
888 KB |
Output is correct |
30 |
Correct |
284 ms |
884 KB |
Output is correct |
31 |
Correct |
245 ms |
880 KB |
Output is correct |
32 |
Correct |
235 ms |
1092 KB |
Output is correct |
33 |
Correct |
191 ms |
972 KB |
Output is correct |
34 |
Correct |
200 ms |
884 KB |
Output is correct |
35 |
Correct |
146 ms |
892 KB |
Output is correct |
36 |
Correct |
184 ms |
844 KB |
Output is correct |
37 |
Correct |
144 ms |
888 KB |
Output is correct |
38 |
Correct |
150 ms |
952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
432 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
420 KB |
Output is correct |
15 |
Correct |
1 ms |
420 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
420 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
253 ms |
880 KB |
Output is correct |
23 |
Correct |
245 ms |
896 KB |
Output is correct |
24 |
Correct |
235 ms |
892 KB |
Output is correct |
25 |
Correct |
236 ms |
844 KB |
Output is correct |
26 |
Correct |
260 ms |
892 KB |
Output is correct |
27 |
Correct |
236 ms |
844 KB |
Output is correct |
28 |
Correct |
244 ms |
868 KB |
Output is correct |
29 |
Correct |
248 ms |
888 KB |
Output is correct |
30 |
Correct |
284 ms |
884 KB |
Output is correct |
31 |
Correct |
245 ms |
880 KB |
Output is correct |
32 |
Correct |
235 ms |
1092 KB |
Output is correct |
33 |
Correct |
191 ms |
972 KB |
Output is correct |
34 |
Correct |
200 ms |
884 KB |
Output is correct |
35 |
Correct |
146 ms |
892 KB |
Output is correct |
36 |
Correct |
184 ms |
844 KB |
Output is correct |
37 |
Correct |
144 ms |
888 KB |
Output is correct |
38 |
Correct |
150 ms |
952 KB |
Output is correct |
39 |
Runtime error |
1 ms |
588 KB |
Execution killed with signal 11 |
40 |
Halted |
0 ms |
0 KB |
- |