#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
#define x first
#define y second
#define int ll
const int N = 2e5 + 10;
const int INF = 1e18;
int n;
vector<int> g[N];
int down[N], value[N];
void dfs(int v, int p) {
down[v] = 1;
vector<int> sons;
for (int u : g[v]) {
if (u == p) {
continue;
}
dfs(u, v);
down[v] += down[u];
sons.push_back(down[u]);
}
sons.push_back(n - down[v]);
value[v] = n - *max_element(all(sons));
}
int dist[N];
int bfs(int from, int lim) {
assert(value[from] >= lim);
queue<int> q;
fill_n(dist, N, INF);
dist[from] = 1;
q.push(from);
int v = from;
while (q.size()) {
v = q.front(); q.pop();
for (int u : g[v]) {
if (value[u] >= lim && dist[u] > dist[v] + 1) {
dist[u] = dist[v] + 1;
q.push(u);
}
}
}
return v;
}
signed main() {
#ifdef LC
assert(freopen("input.txt", "r", stdin));
#endif
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int v, u, i = 0; i < n - 1; ++i) {
cin >> v >> u;
--v, --u;
g[v].push_back(u);
g[u].push_back(v);
}
dfs(0, 0);
int start = (int)(max_element(value, value + n) - value);
for (int i = 1; i <= n; ++i) {
if (i % 2) {
cout << "1\n";
continue;
}
int v = bfs(start, i / 2);
v = bfs(v, i / 2);
cout << dist[v] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
5 ms |
6476 KB |
Output is correct |
3 |
Correct |
4 ms |
6476 KB |
Output is correct |
4 |
Correct |
6 ms |
6476 KB |
Output is correct |
5 |
Correct |
6 ms |
6476 KB |
Output is correct |
6 |
Correct |
6 ms |
6476 KB |
Output is correct |
7 |
Correct |
6 ms |
6476 KB |
Output is correct |
8 |
Correct |
6 ms |
6476 KB |
Output is correct |
9 |
Correct |
6 ms |
6476 KB |
Output is correct |
10 |
Correct |
6 ms |
6476 KB |
Output is correct |
11 |
Correct |
6 ms |
6476 KB |
Output is correct |
12 |
Correct |
6 ms |
6476 KB |
Output is correct |
13 |
Correct |
6 ms |
6476 KB |
Output is correct |
14 |
Correct |
6 ms |
6480 KB |
Output is correct |
15 |
Correct |
6 ms |
6476 KB |
Output is correct |
16 |
Correct |
6 ms |
6560 KB |
Output is correct |
17 |
Correct |
6 ms |
6476 KB |
Output is correct |
18 |
Correct |
6 ms |
6476 KB |
Output is correct |
19 |
Correct |
6 ms |
6476 KB |
Output is correct |
20 |
Correct |
6 ms |
6476 KB |
Output is correct |
21 |
Correct |
6 ms |
6476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
5 ms |
6476 KB |
Output is correct |
3 |
Correct |
4 ms |
6476 KB |
Output is correct |
4 |
Correct |
6 ms |
6476 KB |
Output is correct |
5 |
Correct |
6 ms |
6476 KB |
Output is correct |
6 |
Correct |
6 ms |
6476 KB |
Output is correct |
7 |
Correct |
6 ms |
6476 KB |
Output is correct |
8 |
Correct |
6 ms |
6476 KB |
Output is correct |
9 |
Correct |
6 ms |
6476 KB |
Output is correct |
10 |
Correct |
6 ms |
6476 KB |
Output is correct |
11 |
Correct |
6 ms |
6476 KB |
Output is correct |
12 |
Correct |
6 ms |
6476 KB |
Output is correct |
13 |
Correct |
6 ms |
6476 KB |
Output is correct |
14 |
Correct |
6 ms |
6480 KB |
Output is correct |
15 |
Correct |
6 ms |
6476 KB |
Output is correct |
16 |
Correct |
6 ms |
6560 KB |
Output is correct |
17 |
Correct |
6 ms |
6476 KB |
Output is correct |
18 |
Correct |
6 ms |
6476 KB |
Output is correct |
19 |
Correct |
6 ms |
6476 KB |
Output is correct |
20 |
Correct |
6 ms |
6476 KB |
Output is correct |
21 |
Correct |
6 ms |
6476 KB |
Output is correct |
22 |
Correct |
389 ms |
6832 KB |
Output is correct |
23 |
Correct |
394 ms |
6844 KB |
Output is correct |
24 |
Correct |
390 ms |
6844 KB |
Output is correct |
25 |
Correct |
389 ms |
6836 KB |
Output is correct |
26 |
Correct |
389 ms |
6840 KB |
Output is correct |
27 |
Correct |
410 ms |
6832 KB |
Output is correct |
28 |
Correct |
400 ms |
6852 KB |
Output is correct |
29 |
Correct |
395 ms |
6832 KB |
Output is correct |
30 |
Correct |
390 ms |
6732 KB |
Output is correct |
31 |
Correct |
398 ms |
6832 KB |
Output is correct |
32 |
Correct |
522 ms |
7012 KB |
Output is correct |
33 |
Correct |
552 ms |
7128 KB |
Output is correct |
34 |
Correct |
412 ms |
6884 KB |
Output is correct |
35 |
Correct |
413 ms |
7024 KB |
Output is correct |
36 |
Correct |
405 ms |
6980 KB |
Output is correct |
37 |
Correct |
409 ms |
6860 KB |
Output is correct |
38 |
Correct |
445 ms |
6988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
5 ms |
6476 KB |
Output is correct |
3 |
Correct |
4 ms |
6476 KB |
Output is correct |
4 |
Correct |
6 ms |
6476 KB |
Output is correct |
5 |
Correct |
6 ms |
6476 KB |
Output is correct |
6 |
Correct |
6 ms |
6476 KB |
Output is correct |
7 |
Correct |
6 ms |
6476 KB |
Output is correct |
8 |
Correct |
6 ms |
6476 KB |
Output is correct |
9 |
Correct |
6 ms |
6476 KB |
Output is correct |
10 |
Correct |
6 ms |
6476 KB |
Output is correct |
11 |
Correct |
6 ms |
6476 KB |
Output is correct |
12 |
Correct |
6 ms |
6476 KB |
Output is correct |
13 |
Correct |
6 ms |
6476 KB |
Output is correct |
14 |
Correct |
6 ms |
6480 KB |
Output is correct |
15 |
Correct |
6 ms |
6476 KB |
Output is correct |
16 |
Correct |
6 ms |
6560 KB |
Output is correct |
17 |
Correct |
6 ms |
6476 KB |
Output is correct |
18 |
Correct |
6 ms |
6476 KB |
Output is correct |
19 |
Correct |
6 ms |
6476 KB |
Output is correct |
20 |
Correct |
6 ms |
6476 KB |
Output is correct |
21 |
Correct |
6 ms |
6476 KB |
Output is correct |
22 |
Correct |
389 ms |
6832 KB |
Output is correct |
23 |
Correct |
394 ms |
6844 KB |
Output is correct |
24 |
Correct |
390 ms |
6844 KB |
Output is correct |
25 |
Correct |
389 ms |
6836 KB |
Output is correct |
26 |
Correct |
389 ms |
6840 KB |
Output is correct |
27 |
Correct |
410 ms |
6832 KB |
Output is correct |
28 |
Correct |
400 ms |
6852 KB |
Output is correct |
29 |
Correct |
395 ms |
6832 KB |
Output is correct |
30 |
Correct |
390 ms |
6732 KB |
Output is correct |
31 |
Correct |
398 ms |
6832 KB |
Output is correct |
32 |
Correct |
522 ms |
7012 KB |
Output is correct |
33 |
Correct |
552 ms |
7128 KB |
Output is correct |
34 |
Correct |
412 ms |
6884 KB |
Output is correct |
35 |
Correct |
413 ms |
7024 KB |
Output is correct |
36 |
Correct |
405 ms |
6980 KB |
Output is correct |
37 |
Correct |
409 ms |
6860 KB |
Output is correct |
38 |
Correct |
445 ms |
6988 KB |
Output is correct |
39 |
Execution timed out |
4094 ms |
19692 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |