#include <bits/stdc++.h>
using namespace std;
const int N = (int) 2e5 + 7;
int n, sub[N], sol[N];
vector<int> g[N];
void build(int a, int p = -1) {
sub[a] = 1;
for (auto &b : g[a]) {
if (b == p) continue;
build(b, a);
sub[a] += sub[b];
}
}
void dfs(int a, int p, int thr, int len) {
sol[min(thr, sub[a])] = max(sol[min(thr, sub[a])], len);
for (auto &b : g[a]) {
if (b == p) continue;
dfs(b, a, thr, len + 1);
}
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i < n; i++) {
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
for (int root = 1; root <= n; root++) {
build(root);
for (auto &i : g[root]) {
dfs(i, root, n - sub[i], 1);
}
}
for (int i = n; i >= 1; i--) {
sol[i] = max(sol[i], sol[i + 1]);
}
for (int i = 1; i <= n; i++) {
if (i & 1) {
cout << 1 << "\n";
} else {
cout << sol[i / 2] + 1 << "\n";
}
}
return 0;
}
/**
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5068 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
4 ms |
5016 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
5024 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 |
4 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 |
4 ms |
4940 KB |
Output is correct |
21 |
Correct |
3 ms |
4940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5068 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
4 ms |
5016 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
5024 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 |
4 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 |
4 ms |
4940 KB |
Output is correct |
21 |
Correct |
3 ms |
4940 KB |
Output is correct |
22 |
Correct |
604 ms |
5200 KB |
Output is correct |
23 |
Correct |
598 ms |
5208 KB |
Output is correct |
24 |
Correct |
581 ms |
5316 KB |
Output is correct |
25 |
Correct |
580 ms |
5196 KB |
Output is correct |
26 |
Correct |
625 ms |
5280 KB |
Output is correct |
27 |
Correct |
602 ms |
5196 KB |
Output is correct |
28 |
Correct |
636 ms |
5196 KB |
Output is correct |
29 |
Correct |
601 ms |
5196 KB |
Output is correct |
30 |
Correct |
651 ms |
5196 KB |
Output is correct |
31 |
Correct |
603 ms |
5200 KB |
Output is correct |
32 |
Correct |
600 ms |
5352 KB |
Output is correct |
33 |
Correct |
460 ms |
5452 KB |
Output is correct |
34 |
Correct |
532 ms |
5200 KB |
Output is correct |
35 |
Correct |
327 ms |
5200 KB |
Output is correct |
36 |
Correct |
414 ms |
5228 KB |
Output is correct |
37 |
Correct |
335 ms |
5196 KB |
Output is correct |
38 |
Correct |
420 ms |
5332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5068 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
4 ms |
5016 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
3 ms |
4940 KB |
Output is correct |
8 |
Correct |
3 ms |
4940 KB |
Output is correct |
9 |
Correct |
3 ms |
4940 KB |
Output is correct |
10 |
Correct |
3 ms |
5024 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 |
4 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 |
4 ms |
4940 KB |
Output is correct |
21 |
Correct |
3 ms |
4940 KB |
Output is correct |
22 |
Correct |
604 ms |
5200 KB |
Output is correct |
23 |
Correct |
598 ms |
5208 KB |
Output is correct |
24 |
Correct |
581 ms |
5316 KB |
Output is correct |
25 |
Correct |
580 ms |
5196 KB |
Output is correct |
26 |
Correct |
625 ms |
5280 KB |
Output is correct |
27 |
Correct |
602 ms |
5196 KB |
Output is correct |
28 |
Correct |
636 ms |
5196 KB |
Output is correct |
29 |
Correct |
601 ms |
5196 KB |
Output is correct |
30 |
Correct |
651 ms |
5196 KB |
Output is correct |
31 |
Correct |
603 ms |
5200 KB |
Output is correct |
32 |
Correct |
600 ms |
5352 KB |
Output is correct |
33 |
Correct |
460 ms |
5452 KB |
Output is correct |
34 |
Correct |
532 ms |
5200 KB |
Output is correct |
35 |
Correct |
327 ms |
5200 KB |
Output is correct |
36 |
Correct |
414 ms |
5228 KB |
Output is correct |
37 |
Correct |
335 ms |
5196 KB |
Output is correct |
38 |
Correct |
420 ms |
5332 KB |
Output is correct |
39 |
Execution timed out |
4037 ms |
14564 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |