Mousetrap

On a tree, Dumbo blocks or cleans edges while an edge-averse mouse moves; find the minimum moves to force it into the trap.

Hard8TreeDFSGame theoryGreedyNo attempts yetTime limit5sMemory limit512 MB

Problem

Dumbo the elephant has a huge labyrinth with nn rooms numbered 11 through nn and n1n-1 passages, arranged so that every room is reachable from every other room. A mouse has sneaked into the labyrinth. Dumbo is terribly afraid of mice, so he sets a mousetrap in room tt. The mouse avoids the room with the trap, so Dumbo needs a better plan to bait the mouse into it.

The mouse runs around constantly and never stops, unless it has nowhere to move. It leaves a dirty trail of droppings and footprints in every passage it uses, and it refuses to use a dirty passage again. Dumbo can clean a dirty passage, or block a passage with stones. By blocking passages and cleaning them, he wants to force the mouse into the trap. He would like to do this in as few moves as possible, because he feels highly uncomfortable near a mouse.

Describe this as a game for two players. The mouse tries to maximize the number of Dumbo's moves, and Dumbo tries to win in the smallest number of moves. Dumbo goes first. On his turn he may clean one dirty passage of the labyrinth or block one passage. It does not matter whether the blocked passage is clean or dirty. He cannot unblock a passage. He may also choose to do nothing, and a turn in which he does nothing does not count as a move. When it is the mouse's turn, the mouse chooses a clean unblocked passage leading out of its current room and runs to the room on the other side. If no such passage exists, the mouse does not move.

At the start every passage is clean, the mouse is in room mm, the trap is in room tt, and it is Dumbo's turn. Both sides play optimally. Find the smallest number of moves, counting passages cleaned and passages blocked, that Dumbo needs.

Input

The first line contains the integers nn, tt, and mm, separated by spaces. Each of the next n1n-1 lines contains two integers aa and bb, separated by a space, meaning that a passage joins room aa and room bb.

Note that the input size is large.

Output

Print the minimum number of Dumbo's moves on one line. If the mouse starts in the room with the trap, that is m=tm = t, print 00.

Constraints

  • 1n1061 \le n \le 10^6
  • 1tn1 \le t \le n, 1mn1 \le m \le n

Hint

One scenario that finishes the example in four moves:

  • Dumbo blocks the passage between rooms 44 and 77.
  • The mouse moves to room 66. The passage between rooms 44 and 66 is now dirty.
  • Dumbo blocks the passage between rooms 66 and 88.
  • The mouse cannot move.
  • Dumbo cleans the passage between rooms 44 and 66.
  • The mouse moves to room 44. The passage between rooms 44 and 66 is dirty again.
  • Dumbo blocks the passage between rooms 22 and 33.
  • The mouse moves to room 22. The passage between rooms 22 and 44 is now dirty.
  • Dumbo does nothing.
  • The mouse can only move to room 11 and gets caught in the trap.

Dumbo made four moves.