#include<bits/stdc++.h>
#define ll long long
#define vt vector
#define pb push_back
#define sz(v) (int)v.size()
using namespace std;
const ll base = 107, mod = 1e9 + 7;
const int mxn = 1e5 + 5, inf = 1e9, sq = 400;
int n;
vt<int>adj[mxn + 1];
int tin[mxn + 1], tout[mxn + 1], tt = 0;
int dep[mxn + 1], up[mxn + 1][17], to[mxn + 1], ans[mxn + 1], sz[mxn + 1];
bool vis[mxn + 1];
void dfs_lca(int s, int pre){
for(auto i: adj[s]){
if(i != pre){
dep[i] = dep[s] + 1; up[i][0] = s;
dfs_lca(i, s);
}
}
}
int lca(int u, int v){
if(dep[u] < dep[v])swap(u, v);
int k = dep[u] - dep[v];
for(int i = 0; i < 17; i++){
if(k & (1 << i)){
u = up[u][i];
}
}
if(u == v)return(u);
for(int i = 16; i >= 0; i--){
if(up[u][i] != up[v][i]){
u = up[u][i]; v = up[v][i];
}
}
return(up[u][0]);
}
int dist(int u, int v){
return(dep[u] + dep[v] - 2 * dep[lca(u, v)]);
}
void dfs_euler(int s, int pre){
tin[s] = ++tt; sz[s] = 1;
for(auto i: adj[s]){
if(i != pre){
dfs_euler(i, s); sz[s] += sz[i];
}
}
tout[s] = tt;
}
bool inside(int u, int v){
return(tin[u] <= tin[v] && tout[v] <= tout[u]);
}
void dfs(int s, int pre){
for(int i = 1; i <= n; i++){
if(inside(s, i))continue;
if(vis[i]){
int other = n - sz[to[i]];
ans[min(other, sz[s])] = max(ans[min(other, sz[s])], dist(s, i) + 1);
}else{
int other = sz[i];
ans[min(other, sz[s])] = max(ans[min(other, sz[s])], dist(s, i) + 1);
}
}
vis[s] = 1;
for(auto i: adj[s]){
if(i != pre){
to[s] = i;
dfs(i, s);
}
}
vis[s] = 0;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i < n; i++){
int u, v; cin >> u >> v;
adj[u].pb(v); adj[v].pb(u);
}
dfs_euler(1, -1);
dfs_lca(1, -1);
for(int i = 1; i < 17; i++){
for(int j = 1; j <= n; j++){
up[j][i] = up[up[j][i - 1]][i - 1];
}
}
dfs(1, -1);
for(int i = n / 2; i >= 1; i--){
ans[i] = max(ans[i + 1], ans[i]);
}
for(int i = 1; i <= n; i++){
if(i & 1)cout << 1 << "\n";
else cout << max(1, ans[i / 2]) << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3416 KB |
Output is correct |
2 |
Correct |
1 ms |
5468 KB |
Output is correct |
3 |
Correct |
1 ms |
5468 KB |
Output is correct |
4 |
Correct |
2 ms |
5468 KB |
Output is correct |
5 |
Correct |
1 ms |
5464 KB |
Output is correct |
6 |
Correct |
1 ms |
5720 KB |
Output is correct |
7 |
Correct |
1 ms |
5468 KB |
Output is correct |
8 |
Correct |
2 ms |
5468 KB |
Output is correct |
9 |
Correct |
2 ms |
5468 KB |
Output is correct |
10 |
Correct |
1 ms |
5468 KB |
Output is correct |
11 |
Correct |
1 ms |
5468 KB |
Output is correct |
12 |
Correct |
1 ms |
5468 KB |
Output is correct |
13 |
Correct |
1 ms |
5468 KB |
Output is correct |
14 |
Correct |
1 ms |
5468 KB |
Output is correct |
15 |
Correct |
1 ms |
5468 KB |
Output is correct |
16 |
Correct |
1 ms |
5468 KB |
Output is correct |
17 |
Correct |
1 ms |
5468 KB |
Output is correct |
18 |
Correct |
1 ms |
5572 KB |
Output is correct |
19 |
Correct |
1 ms |
5468 KB |
Output is correct |
20 |
Correct |
1 ms |
5468 KB |
Output is correct |
21 |
Correct |
2 ms |
5568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3416 KB |
Output is correct |
2 |
Correct |
1 ms |
5468 KB |
Output is correct |
3 |
Correct |
1 ms |
5468 KB |
Output is correct |
4 |
Correct |
2 ms |
5468 KB |
Output is correct |
5 |
Correct |
1 ms |
5464 KB |
Output is correct |
6 |
Correct |
1 ms |
5720 KB |
Output is correct |
7 |
Correct |
1 ms |
5468 KB |
Output is correct |
8 |
Correct |
2 ms |
5468 KB |
Output is correct |
9 |
Correct |
2 ms |
5468 KB |
Output is correct |
10 |
Correct |
1 ms |
5468 KB |
Output is correct |
11 |
Correct |
1 ms |
5468 KB |
Output is correct |
12 |
Correct |
1 ms |
5468 KB |
Output is correct |
13 |
Correct |
1 ms |
5468 KB |
Output is correct |
14 |
Correct |
1 ms |
5468 KB |
Output is correct |
15 |
Correct |
1 ms |
5468 KB |
Output is correct |
16 |
Correct |
1 ms |
5468 KB |
Output is correct |
17 |
Correct |
1 ms |
5468 KB |
Output is correct |
18 |
Correct |
1 ms |
5572 KB |
Output is correct |
19 |
Correct |
1 ms |
5468 KB |
Output is correct |
20 |
Correct |
1 ms |
5468 KB |
Output is correct |
21 |
Correct |
2 ms |
5568 KB |
Output is correct |
22 |
Correct |
876 ms |
5784 KB |
Output is correct |
23 |
Correct |
897 ms |
5792 KB |
Output is correct |
24 |
Correct |
879 ms |
5788 KB |
Output is correct |
25 |
Correct |
873 ms |
5792 KB |
Output is correct |
26 |
Correct |
837 ms |
5792 KB |
Output is correct |
27 |
Correct |
849 ms |
5788 KB |
Output is correct |
28 |
Correct |
867 ms |
5788 KB |
Output is correct |
29 |
Correct |
864 ms |
5972 KB |
Output is correct |
30 |
Correct |
856 ms |
5792 KB |
Output is correct |
31 |
Correct |
841 ms |
5792 KB |
Output is correct |
32 |
Correct |
1230 ms |
5904 KB |
Output is correct |
33 |
Correct |
1122 ms |
6228 KB |
Output is correct |
34 |
Correct |
645 ms |
5724 KB |
Output is correct |
35 |
Correct |
602 ms |
5972 KB |
Output is correct |
36 |
Correct |
1222 ms |
5808 KB |
Output is correct |
37 |
Correct |
643 ms |
5724 KB |
Output is correct |
38 |
Correct |
935 ms |
5724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3416 KB |
Output is correct |
2 |
Correct |
1 ms |
5468 KB |
Output is correct |
3 |
Correct |
1 ms |
5468 KB |
Output is correct |
4 |
Correct |
2 ms |
5468 KB |
Output is correct |
5 |
Correct |
1 ms |
5464 KB |
Output is correct |
6 |
Correct |
1 ms |
5720 KB |
Output is correct |
7 |
Correct |
1 ms |
5468 KB |
Output is correct |
8 |
Correct |
2 ms |
5468 KB |
Output is correct |
9 |
Correct |
2 ms |
5468 KB |
Output is correct |
10 |
Correct |
1 ms |
5468 KB |
Output is correct |
11 |
Correct |
1 ms |
5468 KB |
Output is correct |
12 |
Correct |
1 ms |
5468 KB |
Output is correct |
13 |
Correct |
1 ms |
5468 KB |
Output is correct |
14 |
Correct |
1 ms |
5468 KB |
Output is correct |
15 |
Correct |
1 ms |
5468 KB |
Output is correct |
16 |
Correct |
1 ms |
5468 KB |
Output is correct |
17 |
Correct |
1 ms |
5468 KB |
Output is correct |
18 |
Correct |
1 ms |
5572 KB |
Output is correct |
19 |
Correct |
1 ms |
5468 KB |
Output is correct |
20 |
Correct |
1 ms |
5468 KB |
Output is correct |
21 |
Correct |
2 ms |
5568 KB |
Output is correct |
22 |
Correct |
876 ms |
5784 KB |
Output is correct |
23 |
Correct |
897 ms |
5792 KB |
Output is correct |
24 |
Correct |
879 ms |
5788 KB |
Output is correct |
25 |
Correct |
873 ms |
5792 KB |
Output is correct |
26 |
Correct |
837 ms |
5792 KB |
Output is correct |
27 |
Correct |
849 ms |
5788 KB |
Output is correct |
28 |
Correct |
867 ms |
5788 KB |
Output is correct |
29 |
Correct |
864 ms |
5972 KB |
Output is correct |
30 |
Correct |
856 ms |
5792 KB |
Output is correct |
31 |
Correct |
841 ms |
5792 KB |
Output is correct |
32 |
Correct |
1230 ms |
5904 KB |
Output is correct |
33 |
Correct |
1122 ms |
6228 KB |
Output is correct |
34 |
Correct |
645 ms |
5724 KB |
Output is correct |
35 |
Correct |
602 ms |
5972 KB |
Output is correct |
36 |
Correct |
1222 ms |
5808 KB |
Output is correct |
37 |
Correct |
643 ms |
5724 KB |
Output is correct |
38 |
Correct |
935 ms |
5724 KB |
Output is correct |
39 |
Runtime error |
4 ms |
6748 KB |
Execution killed with signal 11 |
40 |
Halted |
0 ms |
0 KB |
- |