#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using ll = long long;
using pii = pair<int, int>;
//#define int ll
const int MOD = 1000000007;
vector<int> elist[200005];
int fa[200005], sz[200005], dep[200005];
pii mxs[200005];
int dfss(int u, int f) {
fa[u] = f, sz[u] = 1;
for (int v : elist[u])
if (v != f)
sz[u] += dfss(v, u), mxs[u] = max(mxs[u], {sz[v], v});
return sz[u];
}
int ans[100005];
int sub[200005];
void dfs2(int u, int f, int x) {
dep[u] = dep[f] + 1;
sub[u] = x;
for (int v : elist[u])
if (v != f)
dfs2(v, u, x);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n - 1; i++) {
int a, b;
cin >> a >> b;
elist[a].pb(b);
elist[b].pb(a);
}
dfss(1, 0);
int rt = 1;
while (mxs[rt].fi > sz[1] / 2)
rt = mxs[rt].se;
dfss(rt, 0);
for (int i : elist[rt])
dfs2(i, rt, i);
vector<pii> ps;
for (int i = 1; i <= n; i++)
if (i != rt)
ps.pb({sz[i], i});
sort(all(ps));
vector<int> active(n + 1), mdp(n + 1);
multiset<int> mdp2;
mdp2.insert(0);
for (int i : elist[rt])
mdp2.insert(mdp[i]);
for (int i = n; i >= 1; i--) {
while (ps.size() && ps.back().fi >= i) {
int u = sub[ps.back().se];
mdp2.erase(mdp2.find(mdp[u]));
mdp[u] = max(mdp[u], dep[ps.back().se]);
mdp2.insert(mdp[u]);
ps.pop_back();
}
if (i <= n / 2)
ans[i] = *mdp2.rbegin() + *next(mdp2.rbegin()) + 1;
}
for (int i = n / 2; 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";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
5028 KB |
Output is correct |
7 |
Correct |
4 ms |
5028 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
5028 KB |
Output is correct |
7 |
Correct |
4 ms |
5028 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
5028 KB |
Output is correct |
7 |
Correct |
4 ms |
5028 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |