Delegation (Platinum)
Time limit2sMemory limit512 MB
Split the edges of a tree into paths that each have at least K edges, and find the largest possible K.
- Level
Medium7 of 10
- Topics
- Tree, Binary search, Greedy, DFS
- Solved
- No attempts yet
Problem
Farmer John's farm consists of pastures () connected by roads, so that any pasture is reachable from any other pasture. In other words, the farm is a tree. But after 28 years of dealing with the tricky algorithmic problems that inevitably arise from trees, FJ has decided that a farm shaped like a tree is too complex. He believes algorithmic problems are simpler on paths.
So he plans to partition the set of roads into several paths and delegate responsibility for these paths to his farm hands. He does not care about the number of paths. However, he wants every path to be as long as possible, so that no farm hand can get away with an asymptotically inefficient algorithm.
Help Farmer John find the largest positive integer such that the roads can be partitioned into paths of length at least .
Input
The first line contains a single integer .
The next lines each contain two space-separated integers and describing an edge between vertices and . Both and are in the range .
Output
Print .
Hint
One possible set of paths is as follows: