# Untitled

unknown
c_cpp
a year ago
1.9 kB
2
Indexable
Never
```#include "bits/stdc++.h"
using namespace std;

using ll = long long;
using ull = unsigned long long;
using db = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<db, db>;
using tiii = tuple<int, int, int>;
using str = string;

#define vt vector
#define pb push_back
#define eb emplace_back
#define ins insert
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

constexpr int maxN = 5000;

vt<int> graph[maxN];

void dfs(int u, int s, vt<vt<int>> &startin, int p = -1, int depth = 0) {
if (startin[depth + 1][s] == 0) startin[depth + 1][s] = startin[depth][s];
startin[depth + 1][s] += sz(graph[u]) - 1;
for (int &g : graph[u]) {
if (g != p) {
dfs(g, s, startin, u, depth + 1);
}
}
}

void solve() {
int n;
cin >> n;
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
u--; v--;
graph[u].pb(v);
graph[v].pb(u);
}
vt<vt<int>> startin(n + 1, vt<int> (n));
fill(all(startin[0]), 1);
for (int i = 0; i < n; i++) {
dfs(i, i, startin);
}
vt<int> maxd(n);
for (int i = 0; i < n; i++) {
maxd[i] = *max_element(all(startin[i]));
}
vt<int> ans(n + 1);
ans[0] = 0;
ans[1] = n - 1;
int curdepth = 0;
for (int i = 2; i <= n; i++) {
if (maxd[curdepth] < i) {
curdepth++;
}
ans[i] = ans[i - 1] - curdepth + (n - 1 - curdepth);
}
debug(ans);
}

signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int tests = 1;
// cin >> tests;
while (tests--) {
solve();
}
return 0;
}```