This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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';
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |