Step Traversing a Tree

No attempts yetTime limit1sMemory limit128 MB

Problem

A graph is a pair (V,E)(V, E), where VV is a finite set of elements called vertices and EE is a set of unordered pairs of distinct vertices, whose elements are called edges. The graph is a tree if for every pair of distinct vertices uu and vv there is exactly one sequence of distinct vertices w0,w1,,wkw_0, w_1, \dots, w_k such that w0=uw_0 = u, wk=vw_k = v and {wi,wi+1}E\{w_i, w_{i+1}\} \in E for every i=0,,k1i = 0, \dots, k-1. The distance between uu and vv in the tree is defined to be kk.

A tree on nn vertices has exactly n1n-1 edges. A tree whose vertices are numbered from 11 to nn is described uniquely by the number of vertices nn together with the n1n-1 pairs of endpoints of its edges.

A traversing order of a tree is a permutation of its vertices, that is, a sequence in which every vertex appears exactly once. For an integer c1c \ge 1, a traversing order has step cc if the distance between every two consecutive vertices in the order is at most cc.

The picture below shows a tree on seven vertices, with vertices drawn as dots and edges as segments joining them.

It is known that every tree has a traversing order with step 33, so the smallest step for which a traversing order exists always exists and is at most 33.

Write a program that reads a tree and outputs the smallest cc for which the tree has a traversing order with step cc.

Input

  • The first line contains a positive integer nn (1n50001 \le n \le 5000), the number of vertices of the tree.
  • Each of the next n1n-1 lines contains one edge, given as two positive integers separated by a single space.

Output

  • Output a single integer: the smallest cc for which the tree has a traversing order with step cc.