#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;
const ll maxn=200005;
vector <ll> A[maxn];
ll child[maxn], used[maxn], ans[maxn];
ll Time, tin[maxn], tout[maxn], dis[maxn];
struct SegTree
{
ll n;
vector <ll> St;
SegTree(ll n): n(n) {St.assign(n*4+1, -1);}
void update(ll i, ll Start, ll End, ll idx, ll val)
{
if (Start==End)
{
St[i]=val;
return;
}
ll mid=(Start+End)/2;
if (mid>=idx) update(i*2, Start, mid, idx, val);
if (mid+1<=idx) update(i*2+1, mid+1, End, idx, val);
St[i]=max(St[i*2], St[i*2+1]);
}
ll query(ll i, ll Start, ll End, ll l, ll r)
{
if (Start>r || End<l)
return -1;
if (Start>=l && End<=r)
return St[i];
ll mid=(Start+End)/2;
if (mid<l) return query(i*2+1, mid+1, End, l, r);
if (mid+1>r) return query(i*2, Start, mid, l, r);
return max(query(i*2, Start, mid, l, r), query(i*2+1, mid+1, End, l, r));
}
};
void getchild(ll u, ll pa)
{
child[u]=1;
for (ll v:A[u])
if (v!=pa && !used[v])
getchild(v, u), child[u]+=child[v];
}
ll findcen(ll u, ll pa, ll n)
{
for (ll v:A[u])
if (v!=pa && !used[v] && child[v]*2>n)
return findcen(v, u, n);
return u;
}
void getlist(ll u, ll pa, ll r, vector <pair<ll, pll>> &a)
{
child[u]=1, tin[u]=++Time, dis[u]=dis[pa]+1;
for (ll v:A[u])
if (v!=pa && !used[v])
getlist(v, u, r, a), child[u]+=child[v];
tout[u]=Time;
a.pb({child[u], {u, r}});
}
void solve(ll u)
{
getchild(u, u);
u=findcen(u, u, child[u]);
vector <pair<ll, pll>> a;
Time=tin[u]=1, dis[u]=0;
for (ll v:A[u])
if (!used[v])
getlist(v, u, v, a);
sort(a.begin(), a.end(), greater<pair<ll, pll>>());
SegTree S(Time);
for (pair<ll, pll> i:a)
{
ll c=i.fi, idx=i.se.fi, r=i.se.se;
ll Max=max(S.query(1, 1, Time, 1, tin[r]-1), S.query(1, 1, Time, tout[r]+1, Time));
if (Max>=0) ans[c]=max(ans[c], dis[idx]+Max+1);
ans[min(c, Time-child[r])]=max(ans[min(c, Time-child[r])], dis[idx]+1);
S.update(1, 1, Time, tin[idx], dis[idx]);
}
used[u]=1;
for (ll v:A[u])
if (!used[v])
solve(v);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll n; cin >> n;
for (ll i=1; i<n; i++)
{
ll u, v; cin >> u >> v;
A[u].pb(v); A[v].pb(u);
}
solve(1);
for (ll i=n; i>=1; i--)
ans[i]=max(ans[i+1], ans[i]);
for (ll i=1; i<=n; i++)
{
if (i%2==1) cout << "1\n";
else cout << max(1ll, ans[i/2]) << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12124 KB |
Output is correct |
2 |
Correct |
3 ms |
12124 KB |
Output is correct |
3 |
Correct |
3 ms |
12124 KB |
Output is correct |
4 |
Correct |
3 ms |
12312 KB |
Output is correct |
5 |
Correct |
3 ms |
12124 KB |
Output is correct |
6 |
Correct |
3 ms |
12124 KB |
Output is correct |
7 |
Correct |
3 ms |
12312 KB |
Output is correct |
8 |
Correct |
4 ms |
12308 KB |
Output is correct |
9 |
Correct |
5 ms |
12124 KB |
Output is correct |
10 |
Correct |
3 ms |
12312 KB |
Output is correct |
11 |
Correct |
3 ms |
12320 KB |
Output is correct |
12 |
Correct |
4 ms |
12316 KB |
Output is correct |
13 |
Correct |
4 ms |
12312 KB |
Output is correct |
14 |
Correct |
4 ms |
12124 KB |
Output is correct |
15 |
Correct |
4 ms |
12120 KB |
Output is correct |
16 |
Correct |
3 ms |
12124 KB |
Output is correct |
17 |
Correct |
3 ms |
12320 KB |
Output is correct |
18 |
Correct |
4 ms |
12124 KB |
Output is correct |
19 |
Correct |
5 ms |
12124 KB |
Output is correct |
20 |
Correct |
4 ms |
12320 KB |
Output is correct |
21 |
Correct |
3 ms |
12124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12124 KB |
Output is correct |
2 |
Correct |
3 ms |
12124 KB |
Output is correct |
3 |
Correct |
3 ms |
12124 KB |
Output is correct |
4 |
Correct |
3 ms |
12312 KB |
Output is correct |
5 |
Correct |
3 ms |
12124 KB |
Output is correct |
6 |
Correct |
3 ms |
12124 KB |
Output is correct |
7 |
Correct |
3 ms |
12312 KB |
Output is correct |
8 |
Correct |
4 ms |
12308 KB |
Output is correct |
9 |
Correct |
5 ms |
12124 KB |
Output is correct |
10 |
Correct |
3 ms |
12312 KB |
Output is correct |
11 |
Correct |
3 ms |
12320 KB |
Output is correct |
12 |
Correct |
4 ms |
12316 KB |
Output is correct |
13 |
Correct |
4 ms |
12312 KB |
Output is correct |
14 |
Correct |
4 ms |
12124 KB |
Output is correct |
15 |
Correct |
4 ms |
12120 KB |
Output is correct |
16 |
Correct |
3 ms |
12124 KB |
Output is correct |
17 |
Correct |
3 ms |
12320 KB |
Output is correct |
18 |
Correct |
4 ms |
12124 KB |
Output is correct |
19 |
Correct |
5 ms |
12124 KB |
Output is correct |
20 |
Correct |
4 ms |
12320 KB |
Output is correct |
21 |
Correct |
3 ms |
12124 KB |
Output is correct |
22 |
Correct |
9 ms |
12836 KB |
Output is correct |
23 |
Correct |
9 ms |
13008 KB |
Output is correct |
24 |
Correct |
11 ms |
12928 KB |
Output is correct |
25 |
Correct |
9 ms |
12928 KB |
Output is correct |
26 |
Correct |
10 ms |
12892 KB |
Output is correct |
27 |
Correct |
10 ms |
12892 KB |
Output is correct |
28 |
Correct |
9 ms |
12892 KB |
Output is correct |
29 |
Correct |
12 ms |
12892 KB |
Output is correct |
30 |
Correct |
10 ms |
12836 KB |
Output is correct |
31 |
Correct |
9 ms |
12952 KB |
Output is correct |
32 |
Correct |
11 ms |
13148 KB |
Output is correct |
33 |
Correct |
10 ms |
13148 KB |
Output is correct |
34 |
Correct |
6 ms |
12892 KB |
Output is correct |
35 |
Correct |
6 ms |
12892 KB |
Output is correct |
36 |
Correct |
11 ms |
12892 KB |
Output is correct |
37 |
Correct |
7 ms |
12888 KB |
Output is correct |
38 |
Correct |
11 ms |
13180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12124 KB |
Output is correct |
2 |
Correct |
3 ms |
12124 KB |
Output is correct |
3 |
Correct |
3 ms |
12124 KB |
Output is correct |
4 |
Correct |
3 ms |
12312 KB |
Output is correct |
5 |
Correct |
3 ms |
12124 KB |
Output is correct |
6 |
Correct |
3 ms |
12124 KB |
Output is correct |
7 |
Correct |
3 ms |
12312 KB |
Output is correct |
8 |
Correct |
4 ms |
12308 KB |
Output is correct |
9 |
Correct |
5 ms |
12124 KB |
Output is correct |
10 |
Correct |
3 ms |
12312 KB |
Output is correct |
11 |
Correct |
3 ms |
12320 KB |
Output is correct |
12 |
Correct |
4 ms |
12316 KB |
Output is correct |
13 |
Correct |
4 ms |
12312 KB |
Output is correct |
14 |
Correct |
4 ms |
12124 KB |
Output is correct |
15 |
Correct |
4 ms |
12120 KB |
Output is correct |
16 |
Correct |
3 ms |
12124 KB |
Output is correct |
17 |
Correct |
3 ms |
12320 KB |
Output is correct |
18 |
Correct |
4 ms |
12124 KB |
Output is correct |
19 |
Correct |
5 ms |
12124 KB |
Output is correct |
20 |
Correct |
4 ms |
12320 KB |
Output is correct |
21 |
Correct |
3 ms |
12124 KB |
Output is correct |
22 |
Correct |
9 ms |
12836 KB |
Output is correct |
23 |
Correct |
9 ms |
13008 KB |
Output is correct |
24 |
Correct |
11 ms |
12928 KB |
Output is correct |
25 |
Correct |
9 ms |
12928 KB |
Output is correct |
26 |
Correct |
10 ms |
12892 KB |
Output is correct |
27 |
Correct |
10 ms |
12892 KB |
Output is correct |
28 |
Correct |
9 ms |
12892 KB |
Output is correct |
29 |
Correct |
12 ms |
12892 KB |
Output is correct |
30 |
Correct |
10 ms |
12836 KB |
Output is correct |
31 |
Correct |
9 ms |
12952 KB |
Output is correct |
32 |
Correct |
11 ms |
13148 KB |
Output is correct |
33 |
Correct |
10 ms |
13148 KB |
Output is correct |
34 |
Correct |
6 ms |
12892 KB |
Output is correct |
35 |
Correct |
6 ms |
12892 KB |
Output is correct |
36 |
Correct |
11 ms |
12892 KB |
Output is correct |
37 |
Correct |
7 ms |
12888 KB |
Output is correct |
38 |
Correct |
11 ms |
13180 KB |
Output is correct |
39 |
Correct |
766 ms |
44096 KB |
Output is correct |
40 |
Correct |
757 ms |
43600 KB |
Output is correct |
41 |
Correct |
654 ms |
44212 KB |
Output is correct |
42 |
Correct |
660 ms |
42920 KB |
Output is correct |
43 |
Correct |
684 ms |
43700 KB |
Output is correct |
44 |
Correct |
685 ms |
43184 KB |
Output is correct |
45 |
Correct |
984 ms |
52844 KB |
Output is correct |
46 |
Correct |
937 ms |
57480 KB |
Output is correct |
47 |
Correct |
309 ms |
34544 KB |
Output is correct |
48 |
Correct |
253 ms |
36164 KB |
Output is correct |
49 |
Correct |
761 ms |
46704 KB |
Output is correct |
50 |
Correct |
303 ms |
43192 KB |
Output is correct |
51 |
Correct |
532 ms |
52280 KB |
Output is correct |