You are given a tree-shaped undirected graph consisting of n nodes labeled 1...n and n-1 edges. The i-th edge connects nodes edges[i][0] and edges[i][1] together.
For a node x in the tree, let d(x) be the distance (the number of edges) from x to its farthest node. Find the min value of d(x) for the given tree.
The tree has the following properties:
x and y in the tree, there's exactly 1 path connecting x and y.Example 1:
Input: n = 6, edges = [[1, 4], [2, 3], [3, 4], [4, 5], [5, 6]]

Output: 2
Example 2:
Input: n = 6, edges = [[1, 3], [4, 5], [5, 6], [3, 2], [3, 4]]

Output: 2
Example 3:
Input: n = 2, edges = [[1, 2]]

Output: 1
Example 4:
Input: n = 10, edges = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10]]

Output: 5
Example 5:
Input: n = 10, edges = [[7, 8], [7, 9], [4, 5], [1, 3], [3, 4], [6, 7], [4, 6], [2, 3], [9, 10]]

Output: 3
You can assume that input is always valid and satisfies all constraints.