#ABC148F. [ABC148F] Playing Tag on Tree

[ABC148F] Playing Tag on Tree

Score : 600600 points

Problem Statement

We have a tree with NN vertices. The ii-th edge connects Vertex AiA_i and BiB_i bidirectionally.

Takahashi is standing at Vertex uu, and Aoki is standing at Vertex vv.

Now, they will play a game of tag as follows:

  • 11. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex.
  • 22. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex.
  • 33. Go back to step 11.

Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible.

Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy.

It can be proved that the game is bound to end.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 1u,vN1 \leq u,v \leq N
  • uvu \neq v
  • 1Ai,BiN1 \leq A_i,B_i \leq N
  • The given graph is a tree.

Input

Input is given from Standard Input in the following format:

NN uu vv

A1A_1 B1B_1

::

AN1A_{N-1} BN1B_{N-1}

Output

Print the number of moves Aoki will perform before the end of the game.

5 4 1
1 2
2 3
3 4
3 5
2

If both players play optimally, the game will progress as follows:

  • Takahashi moves to Vertex 33.
  • Aoki moves to Vertex 22.
  • Takahashi moves to Vertex 55.
  • Aoki moves to Vertex 33.
  • Takahashi moves to Vertex 33.

Here, Aoki performs two moves.

Note that, in each move, it is prohibited to stay at the current vertex.

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