#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
<< ": "; \
dbgh(__VA_ARGS__)
#else
#define cerr \
if (false) \
cerr
#define dbg(...)
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))
constexpr int maxn = 2e5 + 5;
int n, siz[maxn], depth[maxn], ans[maxn];
vector<int> graph[maxn];
void pdfs(int u, int d = 0) {
siz[u] = 1;
depth[u] = d;
for (auto& v : graph[u]) {
graph[v].erase(find(begin(graph[v]), end(graph[v]), u));
pdfs(v, d + 1);
siz[u] += siz[v];
}
}
map<int, int> dfs(int u) {
map<int, int> cur;
auto query = [&](int x, int d) -> void {
auto it = cur.upper_bound(x);
if (it != cur.end()) {
ans[x] = max(ans[x], d + it->second - 2 * depth[u]);
}
if (it != cur.begin()) {
ans[x] = max(ans[x], d + (--it)->second - 2 * depth[u]);
}
};
auto update = [&](int x, int d) -> void {
auto it = cur.lower_bound(x);
if (it != cur.end() && it->second >= d) {
return;
}
while (it != cur.begin() && d >= (--it)->second) {
it = cur.erase(it);
}
cur[x] = d;
};
for (auto& v : graph[u]) {
auto&& cv = dfs(v);
if (sz(cv) > sz(cur)) {
swap(cv, cur);
}
for (auto& [x, d] : cv) {
query(x, d);
}
for (auto& [x, d] : cv) {
update(x, d);
}
}
if (!u) {
dbg(cur.count(1), cur[1]);
}
query(n - siz[u] + 1, depth[u]);
update(siz[u], depth[u]);
return cur;
}
void solve() {
cin >> n;
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
graph[u].push_back(v);
graph[v].push_back(u);
}
pdfs(0);
dfs(0);
for (int i = n; i >= 0; i--) {
ans[i] = max(ans[i], ans[i + 1]);
}
for (int i = 1; i <= n; i++) {
if (i & 1) {
cout << 1 << endl;
} else {
cout << ans[i / 2] + 1 << endl;
}
}
}
int main() {
cin.tie(nullptr);
cin.exceptions(ios::failbit);
ios_base::sync_with_stdio(false);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5028 KB |
Output is correct |
4 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5028 KB |
Output is correct |
4 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5028 KB |
Output is correct |
4 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |