Splitting Trees (4 Points)


Problem Statement

You are given a tree with nn nodes labelled 11 to nn and is rooted at node 11. For 1≤u≤n1 \leq u \leq n we define ∣u∣|u| to be the size (number of nodes) of the subtree rooted at uu. You are to perform the following operation:

  • Pick a node uu such that one of its children vv have the property ∣u∣≤2⋅∣v∣|u| \leq 2 \cdot |v|
  • Change the parent of either uu or vv to be any ww where 1≤w≤n1 \leq w \leq n and such that the tree remains a tree.

After performing any number of operations, determine the smallest length you can make the diameter.

Recall the definition of a tree is a connected graph with no cycles. Recall the diameter of the tree is defined to be the largest distance between any two nodes in the tree, and the distance between two nodes in a tree is the number of edges on the (only) path between those two nodes.

Input Format

Your first line will contain nn, the number of nodes. Your next n−1n - 1 lines will contain two space-separated integers each, uu and vv, meaning there is an edge between uu and vv.

Output Format

Output a single integer representing the smallest length you can make the diameter.

Constraints

  • 1≤n≤1051 \leq n \leq 10^5

Sample Cases

Input 1
7
1 2
1 3
2 4
2 5
4 6
4 7
Output 1
2
Input 2
5
1 2
1 3
3 4
3 5
Output 2
3
Input 3
10
1 2
1 3
1 4
1 5
1 6
1 7
7 8
7 9
7 10
Output 3
3

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.