Fulkerson
Time limit5sMemory limit512 MB
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 intersections and 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 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 of them. The solution will most likely lie somewhere in between, so calculate the minimum possible threat level for every value of .
Input
The first line of input contains a single integer , the number of intersections in the city (). The next lines contain descriptions of the roads. Each description consists of two integers and , denoting that there is a road between these intersections (, ). 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 integers. The -th of these integers must be equal to the minimal possible threat level that could be achieved by using exactly alert groups.