#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << ' ' <<
#define nl << '\n'
const int LIM = 2e5+2, INF = 1e9;
template<class T> struct SegmentTree{
const T ID = -INF;
int n, i; vector<T> a;
SegmentTree(int N) : a((n=N)*2, ID) {}
SegmentTree& operator[](int j){ i=j+n; return *this; }
void operator=(T v){
for(a[i]=v; i/=2; ) a[i] = max(a[2*i], a[2*i+1]); }
int operator()(int l, int r){
T x = ID;
for(l+=n, r+=n+1; l<r; l/=2, r/=2){
if(l & 1) x = max(x, a[l++]);
if(r & 1) x = max(x, a[--r]);
}
return x;
}
};
int n, ans[LIM], s[LIM], mxSz;
set<int> g[LIM];
bool update;
SegmentTree<int> st(LIM);
void init(int u){
s[u] = 1;
for(int v : g[u]) if(!s[v]) init(v), s[u] += s[v];
}
int find(int u){
for(int v : g[u]) if(s[v] > s[u]/2){
s[u] -= s[v], s[v] += s[u];
return find(v);
}
return u;
}
void dfs(int u, int d){
if(update) st[s[u]] = max(st(s[u], s[u]), d);
else ans[s[u]] = max(ans[s[u]], st(s[u], n-1) + d);
if(s[u] <= mxSz) ans[s[u]] = max(ans[s[u]], d);
for(int v : g[u]) if(s[v] < s[u]) dfs(v, d+1);
}
void calc(int v){
ans[s[v]+1] = max(ans[s[v]+1], st(s[v]+1, n-1));
update = 0;
dfs(v, 1);
update = 1;
dfs(v, 1);
}
void decompose(int u){
u = find(u);
for(int v : g[u]) g[v].erase(u);
for(int v : g[u]){
mxSz = s[u] - s[v];
calc(v);
}
for(int i=0; i<s[u]; ++i) st[i+1] = -INF;
auto f = g[u].end();
while(f != g[u].begin()){
int v = *--f;
mxSz = s[u] - s[v];
calc(v);
}
for(int i=0; i<s[u]; ++i) st[i+1] = -INF;
for(int v : g[u]) 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].insert(v);
g[v].insert(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 |
8 ms |
12748 KB |
Output is correct |
2 |
Correct |
8 ms |
12748 KB |
Output is correct |
3 |
Correct |
8 ms |
12748 KB |
Output is correct |
4 |
Correct |
8 ms |
12864 KB |
Output is correct |
5 |
Correct |
8 ms |
12748 KB |
Output is correct |
6 |
Correct |
8 ms |
12848 KB |
Output is correct |
7 |
Correct |
8 ms |
12748 KB |
Output is correct |
8 |
Correct |
9 ms |
12860 KB |
Output is correct |
9 |
Correct |
8 ms |
12860 KB |
Output is correct |
10 |
Correct |
8 ms |
12748 KB |
Output is correct |
11 |
Correct |
8 ms |
12748 KB |
Output is correct |
12 |
Correct |
8 ms |
12812 KB |
Output is correct |
13 |
Correct |
9 ms |
12748 KB |
Output is correct |
14 |
Correct |
8 ms |
12856 KB |
Output is correct |
15 |
Correct |
8 ms |
12748 KB |
Output is correct |
16 |
Correct |
8 ms |
12864 KB |
Output is correct |
17 |
Correct |
8 ms |
12748 KB |
Output is correct |
18 |
Correct |
8 ms |
12748 KB |
Output is correct |
19 |
Correct |
8 ms |
12860 KB |
Output is correct |
20 |
Correct |
8 ms |
12860 KB |
Output is correct |
21 |
Correct |
10 ms |
12748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12748 KB |
Output is correct |
2 |
Correct |
8 ms |
12748 KB |
Output is correct |
3 |
Correct |
8 ms |
12748 KB |
Output is correct |
4 |
Correct |
8 ms |
12864 KB |
Output is correct |
5 |
Correct |
8 ms |
12748 KB |
Output is correct |
6 |
Correct |
8 ms |
12848 KB |
Output is correct |
7 |
Correct |
8 ms |
12748 KB |
Output is correct |
8 |
Correct |
9 ms |
12860 KB |
Output is correct |
9 |
Correct |
8 ms |
12860 KB |
Output is correct |
10 |
Correct |
8 ms |
12748 KB |
Output is correct |
11 |
Correct |
8 ms |
12748 KB |
Output is correct |
12 |
Correct |
8 ms |
12812 KB |
Output is correct |
13 |
Correct |
9 ms |
12748 KB |
Output is correct |
14 |
Correct |
8 ms |
12856 KB |
Output is correct |
15 |
Correct |
8 ms |
12748 KB |
Output is correct |
16 |
Correct |
8 ms |
12864 KB |
Output is correct |
17 |
Correct |
8 ms |
12748 KB |
Output is correct |
18 |
Correct |
8 ms |
12748 KB |
Output is correct |
19 |
Correct |
8 ms |
12860 KB |
Output is correct |
20 |
Correct |
8 ms |
12860 KB |
Output is correct |
21 |
Correct |
10 ms |
12748 KB |
Output is correct |
22 |
Correct |
25 ms |
13328 KB |
Output is correct |
23 |
Correct |
25 ms |
13312 KB |
Output is correct |
24 |
Correct |
25 ms |
13316 KB |
Output is correct |
25 |
Correct |
25 ms |
13332 KB |
Output is correct |
26 |
Correct |
25 ms |
13248 KB |
Output is correct |
27 |
Correct |
24 ms |
13260 KB |
Output is correct |
28 |
Correct |
29 ms |
13324 KB |
Output is correct |
29 |
Correct |
29 ms |
13316 KB |
Output is correct |
30 |
Correct |
27 ms |
13256 KB |
Output is correct |
31 |
Correct |
28 ms |
13260 KB |
Output is correct |
32 |
Correct |
35 ms |
13384 KB |
Output is correct |
33 |
Correct |
34 ms |
13448 KB |
Output is correct |
34 |
Correct |
15 ms |
13216 KB |
Output is correct |
35 |
Correct |
14 ms |
13260 KB |
Output is correct |
36 |
Correct |
32 ms |
13260 KB |
Output is correct |
37 |
Correct |
17 ms |
13320 KB |
Output is correct |
38 |
Correct |
24 ms |
13364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12748 KB |
Output is correct |
2 |
Correct |
8 ms |
12748 KB |
Output is correct |
3 |
Correct |
8 ms |
12748 KB |
Output is correct |
4 |
Correct |
8 ms |
12864 KB |
Output is correct |
5 |
Correct |
8 ms |
12748 KB |
Output is correct |
6 |
Correct |
8 ms |
12848 KB |
Output is correct |
7 |
Correct |
8 ms |
12748 KB |
Output is correct |
8 |
Correct |
9 ms |
12860 KB |
Output is correct |
9 |
Correct |
8 ms |
12860 KB |
Output is correct |
10 |
Correct |
8 ms |
12748 KB |
Output is correct |
11 |
Correct |
8 ms |
12748 KB |
Output is correct |
12 |
Correct |
8 ms |
12812 KB |
Output is correct |
13 |
Correct |
9 ms |
12748 KB |
Output is correct |
14 |
Correct |
8 ms |
12856 KB |
Output is correct |
15 |
Correct |
8 ms |
12748 KB |
Output is correct |
16 |
Correct |
8 ms |
12864 KB |
Output is correct |
17 |
Correct |
8 ms |
12748 KB |
Output is correct |
18 |
Correct |
8 ms |
12748 KB |
Output is correct |
19 |
Correct |
8 ms |
12860 KB |
Output is correct |
20 |
Correct |
8 ms |
12860 KB |
Output is correct |
21 |
Correct |
10 ms |
12748 KB |
Output is correct |
22 |
Correct |
25 ms |
13328 KB |
Output is correct |
23 |
Correct |
25 ms |
13312 KB |
Output is correct |
24 |
Correct |
25 ms |
13316 KB |
Output is correct |
25 |
Correct |
25 ms |
13332 KB |
Output is correct |
26 |
Correct |
25 ms |
13248 KB |
Output is correct |
27 |
Correct |
24 ms |
13260 KB |
Output is correct |
28 |
Correct |
29 ms |
13324 KB |
Output is correct |
29 |
Correct |
29 ms |
13316 KB |
Output is correct |
30 |
Correct |
27 ms |
13256 KB |
Output is correct |
31 |
Correct |
28 ms |
13260 KB |
Output is correct |
32 |
Correct |
35 ms |
13384 KB |
Output is correct |
33 |
Correct |
34 ms |
13448 KB |
Output is correct |
34 |
Correct |
15 ms |
13216 KB |
Output is correct |
35 |
Correct |
14 ms |
13260 KB |
Output is correct |
36 |
Correct |
32 ms |
13260 KB |
Output is correct |
37 |
Correct |
17 ms |
13320 KB |
Output is correct |
38 |
Correct |
24 ms |
13364 KB |
Output is correct |
39 |
Correct |
1930 ms |
37184 KB |
Output is correct |
40 |
Correct |
1856 ms |
36736 KB |
Output is correct |
41 |
Correct |
1941 ms |
37260 KB |
Output is correct |
42 |
Correct |
1811 ms |
37704 KB |
Output is correct |
43 |
Correct |
1957 ms |
37636 KB |
Output is correct |
44 |
Correct |
1827 ms |
37652 KB |
Output is correct |
45 |
Correct |
3204 ms |
40792 KB |
Output is correct |
46 |
Correct |
3134 ms |
43300 KB |
Output is correct |
47 |
Correct |
614 ms |
37692 KB |
Output is correct |
48 |
Correct |
611 ms |
37544 KB |
Output is correct |
49 |
Correct |
2378 ms |
37836 KB |
Output is correct |
50 |
Correct |
832 ms |
37640 KB |
Output is correct |
51 |
Correct |
1814 ms |
42276 KB |
Output is correct |