#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
vector<int> g[N];
int n, sub[N], ans[N], depth[N], anc[N];
void dfs(int x, int p, int root) {
depth[x] = depth[p] + 1;
sub[x] = 1;
if (p == root) {
anc[x] = x;
} else if (x != root) {
anc[x] = anc[p];
}
for (int to : g[x]) {
if (to != p) {
dfs(to, x, root);
sub[x] += sub[to];
}
}
}
int main() {
cin >> n;
if (n > 5000) {
return 0;
}
for (int i = 0; i < n - 1; ++i) {
int u, v; cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
for (int root = 1; root <= n; ++root) {
dfs(root, 0, root);
for (int i = 1; i <= n; ++i) {
int v = min(sub[i], n - sub[anc[i]]);
ans[v] = max(ans[v], depth[i]);
}
}
for (int i = n; i >= 1; --i) {
ans[i] = max(ans[i], ans[i + 1]);
}
for (int i = 1; i <= n; ++i) {
if (i % 2) {
cout << 1 << '\n';
} else {
cout << ans[i / 2] << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5004 KB |
Output is correct |
3 |
Correct |
3 ms |
5004 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
5000 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5004 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
5000 KB |
Output is correct |
16 |
Correct |
3 ms |
5000 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
5008 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5004 KB |
Output is correct |
3 |
Correct |
3 ms |
5004 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
5000 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5004 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
5000 KB |
Output is correct |
16 |
Correct |
3 ms |
5000 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
5008 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 KB |
Output is correct |
22 |
Correct |
376 ms |
5344 KB |
Output is correct |
23 |
Correct |
382 ms |
5244 KB |
Output is correct |
24 |
Correct |
369 ms |
5236 KB |
Output is correct |
25 |
Correct |
388 ms |
5344 KB |
Output is correct |
26 |
Correct |
367 ms |
5204 KB |
Output is correct |
27 |
Correct |
381 ms |
5224 KB |
Output is correct |
28 |
Correct |
386 ms |
5224 KB |
Output is correct |
29 |
Correct |
377 ms |
5228 KB |
Output is correct |
30 |
Correct |
390 ms |
5232 KB |
Output is correct |
31 |
Correct |
368 ms |
5212 KB |
Output is correct |
32 |
Correct |
387 ms |
5312 KB |
Output is correct |
33 |
Correct |
346 ms |
5528 KB |
Output is correct |
34 |
Correct |
326 ms |
5236 KB |
Output is correct |
35 |
Correct |
229 ms |
5228 KB |
Output is correct |
36 |
Correct |
287 ms |
5252 KB |
Output is correct |
37 |
Correct |
232 ms |
5204 KB |
Output is correct |
38 |
Correct |
280 ms |
5512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5004 KB |
Output is correct |
3 |
Correct |
3 ms |
5004 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
5000 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5004 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
5000 KB |
Output is correct |
16 |
Correct |
3 ms |
5000 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
5008 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 KB |
Output is correct |
22 |
Correct |
376 ms |
5344 KB |
Output is correct |
23 |
Correct |
382 ms |
5244 KB |
Output is correct |
24 |
Correct |
369 ms |
5236 KB |
Output is correct |
25 |
Correct |
388 ms |
5344 KB |
Output is correct |
26 |
Correct |
367 ms |
5204 KB |
Output is correct |
27 |
Correct |
381 ms |
5224 KB |
Output is correct |
28 |
Correct |
386 ms |
5224 KB |
Output is correct |
29 |
Correct |
377 ms |
5228 KB |
Output is correct |
30 |
Correct |
390 ms |
5232 KB |
Output is correct |
31 |
Correct |
368 ms |
5212 KB |
Output is correct |
32 |
Correct |
387 ms |
5312 KB |
Output is correct |
33 |
Correct |
346 ms |
5528 KB |
Output is correct |
34 |
Correct |
326 ms |
5236 KB |
Output is correct |
35 |
Correct |
229 ms |
5228 KB |
Output is correct |
36 |
Correct |
287 ms |
5252 KB |
Output is correct |
37 |
Correct |
232 ms |
5204 KB |
Output is correct |
38 |
Correct |
280 ms |
5512 KB |
Output is correct |
39 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |