#include "bits/stdc++.h"
using namespace std;
#define ar array
const int N = 2e5 + 5;
vector<int> edges[N], S[N];
int used[N], ss[N], rr[N];
int sub[N], n, d[N];
void dff(int u, int p = -1){
ss[u] = 1;
for(auto x : edges[u]){
if(x == p) continue;
dff(x, u);
ss[u] += ss[x];
}
}
void dfs(int u, int& C, int n, int p = -1){
sub[u] = 1;
if(p == -1) d[u] = 0;
for(auto x : edges[u]){
if(x == p) continue;
if(!used[x]){
d[x] = d[u] + 1;
dfs(x, C, n, u);
sub[u] += sub[x];
} else {
if(ss[u] > ss[x]) sub[u] += ss[x];
else sub[u] += (::n - ss[u]);
}
}
if(sub[u] > n / 2 && C == -1) C = u;
}
void get(int u, vector<int>& tt, int p = -1){
tt.push_back(u);
for(auto x : edges[u]){
if(used[x] || x == p) continue;
get(x, tt, u);
}
}
struct ST{
int tree[N << 2];
void sett(int i, int v, int lx = 0, int rx = N, int x = 1){
if(lx == rx) { tree[x] = v; return; }
int m = (lx + rx) >> 1;
if(i <= m) sett(i, v, lx, m, x<<1);
else sett(i, v, m+1, rx, x<<1|1);
tree[x] = max(tree[x<<1], tree[x<<1|1]);
}
void umax(int i, int v, int lx = 0, int rx = N, int x = 1){
if(lx == rx) { tree[x] = max(tree[x], v); return; }
int m = (lx + rx) >> 1;
if(i <= m) umax(i, v, lx, m, x<<1);
else umax(i, v, m+1, rx, x<<1|1);
tree[x] = max(tree[x<<1], tree[x<<1|1]);
}
int get(int l, int r, int lx = 0, int rx = N, int x = 1){
if(lx > r || rx < l) return -1e9;
if(lx >= l && rx <= r) return tree[x];
int m = (lx + rx) >> 1;
return max(get(l, r, lx, m, x<<1), get(l, r, m+1, rx, x<<1|1));
}
}tree;
void dec(int u, int n){
int C = -1;
dfs(u, C, n), dfs(C, C, n);
vector<int> tot;
for(auto v : edges[C]){
if(used[v]) continue;
S[v].clear(); get(v, S[v], C);
for(auto x : S[v]){
//~ cout<<sub[x]<<" "<<sub[C] - sub[v]<<endl;
rr[sub[x]] = max(rr[sub[x]], tree.get(sub[x], N) + d[x] + 1);
rr[min(sub[x], sub[C] - sub[v])] =
max(rr[min(sub[x], sub[C] - sub[v])], d[x] + 1);
} for(auto x : S[v]) tree.umax(sub[x], d[x]), tot.push_back(x);
} for(auto x : tot) tree.sett(sub[x], -2e9);
reverse(edges[C].begin(), edges[C].end());
for(auto v : edges[C]){
if(used[v]) continue;
for(auto x : S[v]){
//~ cout<<sub[x]<<" "<<x<<" "<<d[x]<<" "<<tree.get(sub[x], N)<<endl;
rr[sub[x]] = max(rr[sub[x]], tree.get(sub[x], N) + d[x] + 1);
} for(auto x : S[v]) tree.umax(sub[x], d[x]);
} for(auto x : tot) tree.sett(sub[x], -2e9);
used[C] = 1;
for(auto x : edges[C]){
if(used[x]) continue;
dec(x, (int)S[x].size());
}
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
memset(tree.tree, 128, sizeof tree.tree);
cin>>n;
for(int i=1;i<n;i++){
int a, b; cin>>a>>b;
edges[a].push_back(b);
edges[b].push_back(a);
}
dff(1);
dec(1, n);
rr[n] = 1;
//~ for(int i=1;i<=n;i++) cout<<rr[i]<<" ";
//~ cout<<endl;
for(int i=n;i>0;i--) rr[i] = max(rr[i], rr[i+1]);
for(int i=1;i<=n;i++){
if(i&1) cout<<1<<"\n";
else cout<<rr[i/2]<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12748 KB |
Output is correct |
2 |
Correct |
7 ms |
12748 KB |
Output is correct |
3 |
Correct |
6 ms |
12788 KB |
Output is correct |
4 |
Correct |
7 ms |
12828 KB |
Output is correct |
5 |
Correct |
13 ms |
12840 KB |
Output is correct |
6 |
Correct |
8 ms |
12748 KB |
Output is correct |
7 |
Correct |
7 ms |
12748 KB |
Output is correct |
8 |
Correct |
7 ms |
12748 KB |
Output is correct |
9 |
Correct |
7 ms |
12816 KB |
Output is correct |
10 |
Correct |
7 ms |
12748 KB |
Output is correct |
11 |
Correct |
7 ms |
12748 KB |
Output is correct |
12 |
Correct |
7 ms |
12748 KB |
Output is correct |
13 |
Correct |
6 ms |
12752 KB |
Output is correct |
14 |
Correct |
7 ms |
12748 KB |
Output is correct |
15 |
Correct |
6 ms |
12860 KB |
Output is correct |
16 |
Correct |
7 ms |
12748 KB |
Output is correct |
17 |
Correct |
7 ms |
12748 KB |
Output is correct |
18 |
Correct |
6 ms |
12748 KB |
Output is correct |
19 |
Correct |
7 ms |
12748 KB |
Output is correct |
20 |
Correct |
6 ms |
12748 KB |
Output is correct |
21 |
Correct |
7 ms |
12748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12748 KB |
Output is correct |
2 |
Correct |
7 ms |
12748 KB |
Output is correct |
3 |
Correct |
6 ms |
12788 KB |
Output is correct |
4 |
Correct |
7 ms |
12828 KB |
Output is correct |
5 |
Correct |
13 ms |
12840 KB |
Output is correct |
6 |
Correct |
8 ms |
12748 KB |
Output is correct |
7 |
Correct |
7 ms |
12748 KB |
Output is correct |
8 |
Correct |
7 ms |
12748 KB |
Output is correct |
9 |
Correct |
7 ms |
12816 KB |
Output is correct |
10 |
Correct |
7 ms |
12748 KB |
Output is correct |
11 |
Correct |
7 ms |
12748 KB |
Output is correct |
12 |
Correct |
7 ms |
12748 KB |
Output is correct |
13 |
Correct |
6 ms |
12752 KB |
Output is correct |
14 |
Correct |
7 ms |
12748 KB |
Output is correct |
15 |
Correct |
6 ms |
12860 KB |
Output is correct |
16 |
Correct |
7 ms |
12748 KB |
Output is correct |
17 |
Correct |
7 ms |
12748 KB |
Output is correct |
18 |
Correct |
6 ms |
12748 KB |
Output is correct |
19 |
Correct |
7 ms |
12748 KB |
Output is correct |
20 |
Correct |
6 ms |
12748 KB |
Output is correct |
21 |
Correct |
7 ms |
12748 KB |
Output is correct |
22 |
Correct |
19 ms |
13204 KB |
Output is correct |
23 |
Correct |
22 ms |
13188 KB |
Output is correct |
24 |
Correct |
20 ms |
13312 KB |
Output is correct |
25 |
Correct |
18 ms |
13260 KB |
Output is correct |
26 |
Correct |
18 ms |
13280 KB |
Output is correct |
27 |
Correct |
18 ms |
13260 KB |
Output is correct |
28 |
Correct |
20 ms |
13260 KB |
Output is correct |
29 |
Correct |
20 ms |
13180 KB |
Output is correct |
30 |
Correct |
20 ms |
13260 KB |
Output is correct |
31 |
Correct |
23 ms |
13216 KB |
Output is correct |
32 |
Correct |
348 ms |
18280 KB |
Output is correct |
33 |
Correct |
612 ms |
22168 KB |
Output is correct |
34 |
Correct |
12 ms |
13132 KB |
Output is correct |
35 |
Correct |
11 ms |
13132 KB |
Output is correct |
36 |
Correct |
32 ms |
13568 KB |
Output is correct |
37 |
Correct |
12 ms |
13260 KB |
Output is correct |
38 |
Correct |
153 ms |
15488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12748 KB |
Output is correct |
2 |
Correct |
7 ms |
12748 KB |
Output is correct |
3 |
Correct |
6 ms |
12788 KB |
Output is correct |
4 |
Correct |
7 ms |
12828 KB |
Output is correct |
5 |
Correct |
13 ms |
12840 KB |
Output is correct |
6 |
Correct |
8 ms |
12748 KB |
Output is correct |
7 |
Correct |
7 ms |
12748 KB |
Output is correct |
8 |
Correct |
7 ms |
12748 KB |
Output is correct |
9 |
Correct |
7 ms |
12816 KB |
Output is correct |
10 |
Correct |
7 ms |
12748 KB |
Output is correct |
11 |
Correct |
7 ms |
12748 KB |
Output is correct |
12 |
Correct |
7 ms |
12748 KB |
Output is correct |
13 |
Correct |
6 ms |
12752 KB |
Output is correct |
14 |
Correct |
7 ms |
12748 KB |
Output is correct |
15 |
Correct |
6 ms |
12860 KB |
Output is correct |
16 |
Correct |
7 ms |
12748 KB |
Output is correct |
17 |
Correct |
7 ms |
12748 KB |
Output is correct |
18 |
Correct |
6 ms |
12748 KB |
Output is correct |
19 |
Correct |
7 ms |
12748 KB |
Output is correct |
20 |
Correct |
6 ms |
12748 KB |
Output is correct |
21 |
Correct |
7 ms |
12748 KB |
Output is correct |
22 |
Correct |
19 ms |
13204 KB |
Output is correct |
23 |
Correct |
22 ms |
13188 KB |
Output is correct |
24 |
Correct |
20 ms |
13312 KB |
Output is correct |
25 |
Correct |
18 ms |
13260 KB |
Output is correct |
26 |
Correct |
18 ms |
13280 KB |
Output is correct |
27 |
Correct |
18 ms |
13260 KB |
Output is correct |
28 |
Correct |
20 ms |
13260 KB |
Output is correct |
29 |
Correct |
20 ms |
13180 KB |
Output is correct |
30 |
Correct |
20 ms |
13260 KB |
Output is correct |
31 |
Correct |
23 ms |
13216 KB |
Output is correct |
32 |
Correct |
348 ms |
18280 KB |
Output is correct |
33 |
Correct |
612 ms |
22168 KB |
Output is correct |
34 |
Correct |
12 ms |
13132 KB |
Output is correct |
35 |
Correct |
11 ms |
13132 KB |
Output is correct |
36 |
Correct |
32 ms |
13568 KB |
Output is correct |
37 |
Correct |
12 ms |
13260 KB |
Output is correct |
38 |
Correct |
153 ms |
15488 KB |
Output is correct |
39 |
Correct |
1176 ms |
35528 KB |
Output is correct |
40 |
Correct |
1148 ms |
34708 KB |
Output is correct |
41 |
Correct |
1271 ms |
35112 KB |
Output is correct |
42 |
Correct |
1156 ms |
35364 KB |
Output is correct |
43 |
Correct |
1181 ms |
35376 KB |
Output is correct |
44 |
Correct |
1147 ms |
35680 KB |
Output is correct |
45 |
Execution timed out |
4077 ms |
92476 KB |
Time limit exceeded |
46 |
Halted |
0 ms |
0 KB |
- |