#include <bits/stdc++.h>
using namespace std;
#define sp << ' ' <<
#define nl << '\n'
const int LIM = 2e5+2, INF = 1e9;
struct FenwickTree{
vector<int> a; int n, s;
FenwickTree(int N) : a((n=N)+1, -INF) {}
void update(int i, int v){
i = n - i;
for(; i<=n; i+=i&-i) a[i] = max(a[i], v);
}
int operator()(int i){
i = n - i, s = -INF;
for(; i>=1; i-=i&-i) s = max(s, a[i]);
return s;
}
};
int n, ans[LIM], s[LIM], mxSz;
vector<int> g[LIM];
bool r[LIM], update;
FenwickTree f(0);
void init(int u){
s[u] = 1;
for(int v : g[u]) if(!s[v]) init(v), s[u] += s[v];
}
void find(int &u){
for(int q=1; q; ){
q = 0;
for(int v : g[u]) if(!r[v] && s[v] > s[u]/2){
s[u] -= s[v], s[v] += s[u], u = v, q = 1;
break;
}
}
}
void dfs(int u, int d){
if(update) f.update(s[u], d);
else ans[s[u]] = max(ans[s[u]], f(s[u]) + d);
if(s[u] <= mxSz) ans[s[u]] = max(ans[s[u]], d);
for(int v : g[u]) if(!r[v] && s[v] < s[u]) dfs(v, d+1);
}
void calc(int u){
f = FenwickTree(s[u] + 1);
for(int v : g[u]) if(!r[v]){
ans[s[v]+1] = max(ans[s[v]+1], f(s[v]+1));
mxSz = s[u] - s[v];
update = 0, dfs(v, 1);
update = 1, dfs(v, 1);
}
}
void decompose(int u){
find(u), r[u] = 1;
calc(u);
reverse(g[u].begin(), g[u].end());
calc(u);
for(int v : g[u]) if(!r[v]) decompose(v);
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i=1; i<n; ++i){
int u, v; cin >> u >> v;
--u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
init(0);
decompose(0);
for(int i=n; --i; ) ans[i] = max(ans[i], ans[i+1]);
for(int i=1; i<=n; ++i){
if(i & 1) cout << 1 nl;
else cout << ans[i/2]+1 nl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4928 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
4 ms |
4960 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4976 KB |
Output is correct |
10 |
Correct |
4 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
3 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4928 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
4 ms |
4960 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4976 KB |
Output is correct |
10 |
Correct |
4 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
3 ms |
4940 KB |
Output is correct |
22 |
Correct |
8 ms |
5124 KB |
Output is correct |
23 |
Correct |
10 ms |
5196 KB |
Output is correct |
24 |
Correct |
8 ms |
5228 KB |
Output is correct |
25 |
Correct |
10 ms |
5220 KB |
Output is correct |
26 |
Correct |
8 ms |
5196 KB |
Output is correct |
27 |
Correct |
10 ms |
5156 KB |
Output is correct |
28 |
Correct |
8 ms |
5196 KB |
Output is correct |
29 |
Correct |
8 ms |
5196 KB |
Output is correct |
30 |
Correct |
8 ms |
5224 KB |
Output is correct |
31 |
Correct |
8 ms |
5220 KB |
Output is correct |
32 |
Correct |
10 ms |
5188 KB |
Output is correct |
33 |
Correct |
9 ms |
5340 KB |
Output is correct |
34 |
Correct |
7 ms |
5196 KB |
Output is correct |
35 |
Correct |
6 ms |
5196 KB |
Output is correct |
36 |
Correct |
10 ms |
5196 KB |
Output is correct |
37 |
Correct |
6 ms |
5196 KB |
Output is correct |
38 |
Correct |
7 ms |
5196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4928 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
4 ms |
4960 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4976 KB |
Output is correct |
10 |
Correct |
4 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Correct |
3 ms |
4940 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
4940 KB |
Output is correct |
17 |
Correct |
3 ms |
4940 KB |
Output is correct |
18 |
Correct |
3 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4940 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
3 ms |
4940 KB |
Output is correct |
22 |
Correct |
8 ms |
5124 KB |
Output is correct |
23 |
Correct |
10 ms |
5196 KB |
Output is correct |
24 |
Correct |
8 ms |
5228 KB |
Output is correct |
25 |
Correct |
10 ms |
5220 KB |
Output is correct |
26 |
Correct |
8 ms |
5196 KB |
Output is correct |
27 |
Correct |
10 ms |
5156 KB |
Output is correct |
28 |
Correct |
8 ms |
5196 KB |
Output is correct |
29 |
Correct |
8 ms |
5196 KB |
Output is correct |
30 |
Correct |
8 ms |
5224 KB |
Output is correct |
31 |
Correct |
8 ms |
5220 KB |
Output is correct |
32 |
Correct |
10 ms |
5188 KB |
Output is correct |
33 |
Correct |
9 ms |
5340 KB |
Output is correct |
34 |
Correct |
7 ms |
5196 KB |
Output is correct |
35 |
Correct |
6 ms |
5196 KB |
Output is correct |
36 |
Correct |
10 ms |
5196 KB |
Output is correct |
37 |
Correct |
6 ms |
5196 KB |
Output is correct |
38 |
Correct |
7 ms |
5196 KB |
Output is correct |
39 |
Correct |
749 ms |
14376 KB |
Output is correct |
40 |
Correct |
721 ms |
13980 KB |
Output is correct |
41 |
Correct |
825 ms |
14248 KB |
Output is correct |
42 |
Correct |
706 ms |
14316 KB |
Output is correct |
43 |
Correct |
770 ms |
14356 KB |
Output is correct |
44 |
Correct |
715 ms |
14268 KB |
Output is correct |
45 |
Correct |
1223 ms |
17796 KB |
Output is correct |
46 |
Correct |
903 ms |
20832 KB |
Output is correct |
47 |
Correct |
235 ms |
14140 KB |
Output is correct |
48 |
Correct |
192 ms |
14508 KB |
Output is correct |
49 |
Correct |
605 ms |
14984 KB |
Output is correct |
50 |
Correct |
232 ms |
15020 KB |
Output is correct |
51 |
Correct |
512 ms |
19276 KB |
Output is correct |