Conspirație

Time limit: 3s Memory limit: 256MB Input: Output:

At the beginning of the year 2026, the entire planet was infected by multiple viruses. In each country, a unique virus appeared. Due to the economic crisis that came along with these pandemics, international travel was restricted such that there exists a single route between any two distinct countries.

World leaders agreed that each day only one road among the remaining ones would be available for traversal. When a route between two countries is opened, the people of the two states infect each other, and the virus chosen by the leaders between the two remains alive in both states.

World leaders hired you to determine the minimum number of days needed for the entire planet to be infected by a single virus.

Task

Formally, you are given the list of edges of a tree with nn nodes. Initially, state ii is considered to be infected with the virus virusi=ivirus_i = i. On day xx, the edge xx modulo (n1)(n - 1) (let it be UVU - V) will be available and we are forced to perform one of the following two operations:

  1. virusU=virusVvirus_U = virus_V (node UU receives the value of node VV)
  2. virusV=virusUvirus_V = virus_U (node VV receives the value of node UU)

Edges and days are indexed starting from 00.

You are asked to output the minimum number of days after which it is guaranteed that all nodes will have the same value, assuming you apply an optimal strategy.

Input Data

On the first line, a single natural number nn is read, representing the number of nodes in the tree.

On the next n1n - 1 lines, the edges that form the tree are read. On each line there are two distinct natural numbers between 11 and nn, representing the endpoints of the respective edge.

Output Data

You must output a single natural number representing the minimum number of days required to infect the entire planet with the same virus.

Constraints

  • 1n10000001 \le n \le 1\,000\,000
# Points Restrictions
1 30 1n10001 \le n \le 1\,000
2 70 No additional constraints

Example 1

stdin

4
1 3
2 4
2 3

stdout

4

Explanation

In the first example, the tree is a chain of the form 11 -- 33 -- 22 -- 44. On day 00, the edge 11 -- 33 will be available and we will choose virus1virus_1 to receive the value of virus3virus_3. On day 11, the edge 22 -- 44 will be available and we will choose virus4virus_4 to receive the value of virus2virus_2. On day 22, we will choose virus3virus_3 to receive the value of virus2virus_2, and on day 33 we will choose virus1virus_1 to receive the value of virus3virus_3. After four days, all nodes will have the same value. It can be shown that the nodes cannot obtain the same value in fewer than four days.

After each step, the array virusvirus looks as follows:

  1. [1,2,3,4][1 , 2 , 3 , 4] (initial)
  2. [3,2,3,4][3 , 2 , 3 , 4]
  3. [3,2,3,2][3 , 2 , 3 , 2]
  4. [3,2,2,2][3 , 2 , 2 , 2]
  5. [2,2,2,2][2 , 2 , 2 , 2]

Example 2

stdin

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

stdout

20


* Gomory and Hu would have solved this problem, but at the moment they are very busy securing the APT network.

Log in or sign up to be able to send submissions!