Under construction

Still being built. Things may change

Fulkerson

Time limit5sMemory limit512 MB

Summary
Given a tree with N nodes, find for each K from 1 to N the smallest possible maximum distance from any node to its nearest of K chosen nodes.
Level

Hard9 of 10

Topics
Tree, Dynamic programming, Binary search
Solved
No attempts yet

Problem

Lester and Delbert already know how to disconnect a railroad network by exploding the minimum possible number of railways. That turned out to be pretty easy, so they went on to another interesting problem: how to rob the Federal Bank. Now they need your help preparing an escape plan.

The bank is located in a city with NN intersections and N−1N - 1 bidirectional roads connecting them. All roads have the same length. It is possible to get from any intersection to any other using the road network.

To ensure a safe escape, Lester and Delbert plan to hire KK alert groups and place them at different intersections to collect information about police movements. Once the placement is fixed, for each intersection they compute the minimum number of roads one needs to travel to reach some alert group. The maximum of this value over all intersections is called the threat level of the placement.

Lester wants to hire only one alert group, while Delbert prefers to use NN of them. The solution will most likely lie somewhere in between, so calculate the minimum possible threat level for every value of KK.

Input

The first line of input contains a single integer NN, the number of intersections in the city (1≤N≤150 0001 \leq N \leq 150\,000). The next N−1N-1 lines contain descriptions of the roads. Each description consists of two integers uu and vv, denoting that there is a road between these intersections (1≤u,v≤N1 \le u, v \le N, u≠vu \neq v). It is guaranteed that it is possible to get from any intersection to any other using the road network.

Output

The output must consist of NN integers. The ii-th of these integers must be equal to the minimal possible threat level that could be achieved by using exactly ii alert groups.

Hint

Number of alert groupsOne of the optimal placementsOptimal distance
173
27, 92
31, 5, 62
41, 5, 7, 91
51, 5, 7, 9, 101
61, 5, 7, 8, 9, 101
71, 5, 6, 7, 8, 9, 101
81, 4, 5, 6, 7, 8, 9, 101
91, 3, 4, 5, 6, 7, 8, 9, 101
101, 2, 3, 4, 5, 6, 7, 8, 9, 100

Examples1

  1. Example 1

    Input
    10
    7 3
    6 9
    9 7
    1 7
    10 7
    8 5
    4 1
    5 9
    2 5
    
    Expected output
    3 2 2 1 1 1 1 1 1 0