#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)
const int MN = 400;
int n, u, v, ans[MN], dep[MN], sz[MN], dist[MN][MN];
vector<int> a[MN];
pii ed[MN];
void dfs(int cur, int par, int d) {
sz[cur] = 1;
dep[cur] = d;
for (int nxt : a[cur]) {
if (nxt == par) continue;
dfs(nxt, cur, d + 1);
sz[cur] += sz[nxt];
}
}
int32_t main() {
boost();
memset(dist, 0x3f, sizeof(dist));
cin >> n;
for (int i = 1; i <= n; i++) dist[i][i] = 0;
for (int i = 1; i < n; i++) {
cin >> u >> v;
dist[u][v] = dist[v][u] = 1;
a[u].push_back(v);
a[v].push_back(u);
ed[i] = {u, v};
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
for (int i = 1; i <= n; i++) {
dfs(i, 0, 0);
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
if (i == j || i == k || dist[j][k] != dep[j] + dep[k]) continue;
ans[min(sz[j], sz[k]) * 2] = max(ans[min(sz[j], sz[k]) * 2], dep[j] + dep[k] + 1);
}
}
}
for (int i = 1; i < n; i++) {
dfs(ed[i].f, ed[i].s, 0);
dfs(ed[i].s, ed[i].f, 0);
ans[min(sz[ed[i].f], sz[ed[i].s]) * 2] = max(ans[min(sz[ed[i].f], sz[ed[i].s]) * 2], 2ll);
}
for (int i = n; i > 0; i--) ans[i] = max({1ll, ans[i + 1], ans[i]});
for (int i = 1; i <= n; i++) printf("%lld\n", i % 2 ? 1 : ans[i]);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1484 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1484 KB |
Output is correct |
8 |
Correct |
2 ms |
1592 KB |
Output is correct |
9 |
Correct |
2 ms |
1484 KB |
Output is correct |
10 |
Correct |
8 ms |
1484 KB |
Output is correct |
11 |
Correct |
1 ms |
1488 KB |
Output is correct |
12 |
Correct |
2 ms |
1484 KB |
Output is correct |
13 |
Correct |
2 ms |
1484 KB |
Output is correct |
14 |
Correct |
1 ms |
1484 KB |
Output is correct |
15 |
Correct |
2 ms |
1592 KB |
Output is correct |
16 |
Correct |
1 ms |
1484 KB |
Output is correct |
17 |
Correct |
1 ms |
1484 KB |
Output is correct |
18 |
Correct |
2 ms |
1488 KB |
Output is correct |
19 |
Correct |
1 ms |
1484 KB |
Output is correct |
20 |
Correct |
1 ms |
1484 KB |
Output is correct |
21 |
Correct |
2 ms |
1484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1484 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1484 KB |
Output is correct |
8 |
Correct |
2 ms |
1592 KB |
Output is correct |
9 |
Correct |
2 ms |
1484 KB |
Output is correct |
10 |
Correct |
8 ms |
1484 KB |
Output is correct |
11 |
Correct |
1 ms |
1488 KB |
Output is correct |
12 |
Correct |
2 ms |
1484 KB |
Output is correct |
13 |
Correct |
2 ms |
1484 KB |
Output is correct |
14 |
Correct |
1 ms |
1484 KB |
Output is correct |
15 |
Correct |
2 ms |
1592 KB |
Output is correct |
16 |
Correct |
1 ms |
1484 KB |
Output is correct |
17 |
Correct |
1 ms |
1484 KB |
Output is correct |
18 |
Correct |
2 ms |
1488 KB |
Output is correct |
19 |
Correct |
1 ms |
1484 KB |
Output is correct |
20 |
Correct |
1 ms |
1484 KB |
Output is correct |
21 |
Correct |
2 ms |
1484 KB |
Output is correct |
22 |
Runtime error |
4 ms |
3020 KB |
Execution killed with signal 11 |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1484 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1484 KB |
Output is correct |
8 |
Correct |
2 ms |
1592 KB |
Output is correct |
9 |
Correct |
2 ms |
1484 KB |
Output is correct |
10 |
Correct |
8 ms |
1484 KB |
Output is correct |
11 |
Correct |
1 ms |
1488 KB |
Output is correct |
12 |
Correct |
2 ms |
1484 KB |
Output is correct |
13 |
Correct |
2 ms |
1484 KB |
Output is correct |
14 |
Correct |
1 ms |
1484 KB |
Output is correct |
15 |
Correct |
2 ms |
1592 KB |
Output is correct |
16 |
Correct |
1 ms |
1484 KB |
Output is correct |
17 |
Correct |
1 ms |
1484 KB |
Output is correct |
18 |
Correct |
2 ms |
1488 KB |
Output is correct |
19 |
Correct |
1 ms |
1484 KB |
Output is correct |
20 |
Correct |
1 ms |
1484 KB |
Output is correct |
21 |
Correct |
2 ms |
1484 KB |
Output is correct |
22 |
Runtime error |
4 ms |
3020 KB |
Execution killed with signal 11 |
23 |
Halted |
0 ms |
0 KB |
- |