Under construction

Still being built. Things may change

Guardian of the Forest

Time limit1sMemory limit1024 MB

Summary
Given a tree where fire starts at vertex a and Geunseong stands at vertex b, find the maximum number of vertices where he can copy data before the fire reaches him.
Level

Medium6 of 10

Topics
Tree, DFS, Dynamic programming
Solved
No attempts yet

Problem

Geunseong is very interested in trees.

Geunseong is a druid and the guardian of the forest who takes care of a tree. The tree he manages has the form of a tree graph with NN vertices. Geunseong values every vertex, so he assigned each of the NN vertices a unique number from 11 to NN.

One day, the villain Yeongdo, who has always envied Geunseong's wonderful tree, set it on fire. To preserve the tree as well as possible, Geunseong must copy as much of the data stored at each vertex as he can before the tree burns away completely.

Initially, Yeongdo set fire to vertex aa, and Geunseong stands on vertex bb, which has not burned. On an unburned vertex, Geunseong may choose and perform one of the following actions.

  • Copy: copy the data at the current vertex. This takes no time. However, data cannot be copied again at a vertex where it has already been copied.
  • Move: move along an edge to one of the neighboring unburned vertices.
  • Wait: stay at the current vertex without moving.

If Geunseong moves or waits, fire spreads during that time from each burning vertex to its unburned neighbors.

If Geunseong's next action puts him on a burning vertex, he immediately gives up preserving the tree and escapes. If fire spreads to a vertex at the same moment Geunseong arrives there, he cannot copy data at that vertex.

Your task is to find the maximum number of vertices at which Geunseong can copy data before he escapes, and report it to him.

Input

The first line contains the number of vertices NN of the tree.

Each of the next N−1N-1 lines contains two integers uu and vv, separated by a space, meaning there is an edge between vertex uu and vertex vv.

The line after those N−1N-1 lines contains the numbers of the vertex aa that is initially on fire and the vertex bb where Geunseong stands, separated by a space.

Output

Print the maximum number of vertices at which Geunseong can copy data before he escapes, over all possible cases.

Constraints

  • 2≤N≤100 0002 \le N \le 100\,000
  • 1≤a,b,u,v≤N1 \le a, b, u, v \le N
  • a≠ba \neq b
  • All numbers in the input are integers.
  • Every tree in the input is a valid tree.

Hint

The figure below shows the tree from Sample 1. In this problem, a tree is a simple connected graph with no cycles. The figure of the sample is also a simple connected graph with no cycles.

In this sample, the maximum number of vertices where Geunseong can copy data is 3. One optimal plan is to move 44(bb)→22→11 without waiting, copying the data at every vertex.

Examples3

  1. Example 1

    Input
    8
    1 2
    2 3
    2 4
    5 4
    4 6
    7 6
    6 8
    5 4
    
    Expected output
    3
    
  2. Example 2

    Input
    13
    10 11
    6 7
    7 11
    7 3
    1 3
    3 4
    12 8
    8 4
    4 5
    5 2
    5 9
    9 13
    13 7
    
    Expected output
    5
    
  3. Example 3

    Input
    3
    1 2
    2 3
    1 3
    
    Expected output
    1