Under construction

Still being built. Things may change

Lost in the Night

Interview

Time limit2sMemory limit512 MB

Summary
On a tree, a walker starting at node A repeatedly picks a uniformly random neighbor until reaching hotel B or C; find the probability of hitting B first.
Level

Medium6 of 10

Topics
Probability, Graph, Tree, Math
Solved
No attempts yet

Problem

A city in Nlogonia has NN roundabouts and N−1N-1 streets. Each street joins two different roundabouts, and the streets alone let you travel from any roundabout to any other one.

The city has only two hotels. The cheap one is on roundabout BB and the expensive one is on roundabout CC. A tourist came to the city for a friend's birthday party, held at a club on roundabout AA. He booked neither hotel, and the night is pleasant, so after the party he decided to walk the streets and roundabouts until he runs into a hotel. He will stay at the first hotel he finds.

The plan turned out harder than he expected. He does not know the city and he drank more than he should have, so every street looks the same to him. He settled on this strategy. At each roundabout he picks one of the streets leaving it, all with the same probability, and takes that street to another roundabout. He stops as soon as he reaches a roundabout that has a hotel on it. Because he cannot tell the streets apart, he sometimes picks the street he just walked in on.

Given the street layout, the location AA of the party, the location BB of the cheap hotel and the location CC of the expensive hotel, write a program that computes the probability that the tourist reaches the cheap hotel before the expensive one.

Input

The input holds several test cases and ends at end of file. The first line of a test case has four integers NN, AA, BB and CC: the number of roundabouts, the roundabout where the birthday party is held, the roundabout with the cheap hotel, and the roundabout with the expensive hotel. Each of the next N−1N-1 lines has two integers XX and YY, meaning a street joins roundabouts XX and YY.

Constraints

  • 3≤N≤1003 \le N \le 100
  • The input has at most 100 test cases.
  • B≠CB \ne C, A≠BA \ne B, A≠CA \ne C
  • 1≤A,B,C≤N1 \le A, B, C \le N
  • 1≤X,Y≤N1 \le X, Y \le N
  • X≠YX \ne Y
  • The N−1N-1 streets always connect every roundabout.

Output

For each test case print one line with the probability that the tourist reaches the cheap hotel before the expensive one, rounded to six decimal places. Print all six digits, so a probability of 0 is 0.000000 and a probability of 1 is 1.000000.

Examples2

  1. Example 1

    Input
    4 1 2 3
    1 4
    2 4
    3 4
    5 3 1 5
    1 2
    2 3
    3 4
    4 5
    
    Expected output
    0.500000
    0.500000
    
  2. Example 2

    Input
    3 2 1 3
    1 2
    2 3
    3 2 3 1
    2 3
    1 2
    4 1 2 4
    1 2
    2 3
    3 4
    4 1 4 2
    1 2
    2 3
    3 4
    
    Expected output
    0.500000
    0.500000
    1.000000
    0.000000