#P7565. [JOISC 2021] ビーバーの会合 2 (Day3)

[JOISC 2021] ビーバーの会合 2 (Day3)

Description

You are given a tree with NN vertices. There is one person at each vertex, and they want to hold a secret meeting.

Suppose a secret meeting has PP participants, and these PP people are located at vertices p1,p2,,pPp_1, p_2, \cdots, p_P. If a vertex kk minimizes the following value among all vertices (where d(a,b)d(a,b) is the distance between vertices aa and bb, and kk does not need to satisfy k{p1,p2,,pP}k \in \{p_1,p_2,\cdots,p_P\}):

i=1Pd(k,pi)\sum\limits_{i=1}^P d(k,p_i)

then vertex kk is called expected. The expected value of the meeting is the number of expected vertices in the whole tree.

For each j[1,N]j \in [1,N], find the maximum possible expected value of a meeting with exactly jj participants.

Input Format

The first line contains an integer NN, the number of vertices in the tree.

Each of the next N1N-1 lines contains two integers Ai,BiA_i, B_i, representing an edge.

Output Format

Output NN lines, each containing one integer. The jj-th line should contain the answer when the meeting has jj participants.

5
1 2
2 3
4 2
3 5
1
4
1
2
1
7
1 2
2 3
3 4
4 5
2 6
3 7
1
5
1
3
1
2
1

Hint

Explanation of Sample 1

Below we denote βk=i=1Pd(k,pi)\displaystyle\beta_k=\sum\limits_{i=1}^P d(k,p_i).

Using the tree in Sample 1 as an example, suppose the participants are the person at vertex 11 and the person at vertex 33. Then:

  • P=2P=2, pi={1,3}p_i=\{1,3\}.
  • β1=2\beta_1=2.
  • β2=2\beta_2=2.
  • β3=2\beta_3=2.
  • β4=4\beta_4=4.
  • β5=4\beta_5=4.

mini=15{βi}=2\min\limits_{i=1}^5\{\beta_i\}=2. The vertices that satisfy the condition are 1,2,31,2,3, so the expected value of this meeting is 33.

Constraints

This problem uses bundled testdata.

  • Subtask 1 (4 pts): N16N \le 16.
  • Subtask 2 (16 pts): N4000N \le 4000.
  • Subtask 3 (80 pts): No special constraints.

For 100%100\% of the data, 1N2×1051 \le N \le 2 \times 10^5, 1Ai,BiN1 \le A_i, B_i \le N.

Notes

Translated from The 20th Japanese Olympiad in Informatics Spring Training Camp, Day3 C ビーバーの会合 2 (Meetings 2) English version.

Translated by ChatGPT 5