Under construction

Still being built. Things may change

Delegation (Platinum)

Time limit2sMemory limit512 MB

Summary
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 NN pastures (2≤N≤1052 \leq N \leq 10^5) connected by N−1N-1 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 KK such that the roads can be partitioned into paths of length at least KK.

Input

The first line contains a single integer NN.

The next N−1N-1 lines each contain two space-separated integers aa and bb describing an edge between vertices aa and bb. Both aa and bb are in the range 1…N1 \ldots N.

Output

Print KK.

Hint

One possible set of paths is as follows: 2−1−6−7−8,3−1−4−52-1-6-7-8, 3-1-4-5

Examples1

  1. Example 1

    Input
    8
    1 2
    1 3
    1 4
    4 5
    1 6
    6 7
    7 8
    
    Expected output
    3