Kitten and Roomba

시간 제한15초메모리 제한1024 MB

요약
나무, 고양이의 시작 방, 로봄바의 이동 경로가 주어질 때, 들킬 때마다 이웃 방으로 무작위로 도망치는 고양이가 잡히는 횟수의 기댓값을 구한다.
난이도

보통10점 중 7점

유형
트리, 확률, DFS, 구현
정답자
아직 제출이 없습니다

문제

A little kitten of Bituś, Kapitan, does love sleeping! Sadly, the average quality of Kapitan's sleep has decreased significantly after its owner decided to buy Roomba -- a robot vacuum cleaner. It seems the kitten is scared of Roomba as... well, it is fairly scared.

Bituś's house consists of nn rooms connected by n−1n-1 two-way corridors in such a way that it is possible to reach any room from any other one. Bituś noticed that whenever Roomba enters a room with Kapitan inside, the kitten awakes instantly and runs away to one of the neighbouring rooms, where it returns back to dreaming about playing with mice. Frightened Kapitan escapes the room blindly, so if there exists more than one room directly connected to the current one, then every neighbouring room is equally likely to chosen by Kapitan (in particular, it can escape to the room from which Roomba has just came from).

During one particularly long night shift at work, Bituś opened the Roomba app and observed that during today's cleaning it visited rooms a_1,…,a_ma\_1, \dots, a\_m (in this order). A room can appear more than once in this sequence, but every two neighbouring rooms must be directly connected to each other. Bituś also remembers that initially the kitten had been sleeping in the room cc. Moreover, it must hold that a_1≠ca\_1 \neq c because observant Kapitan would never ever sleep in one room with Roomba!

Now Bituś wonders what is the expected value of the number of times Roomba has woken Kapitan during the cleaning session. Please help Bituś to find the answer so he can finally return back to work.

입력

The first line of input contains the number of test cases zz (1≤z≤6,0001 \le z \le 6\\,000). The descriptions of the test cases follow.

The first line of a test case contains two integers nn, cc (2≤n≤1,000,0002 \leq n \leq 1\\,000\\,000, 1≤c≤n1 \leq c \leq n), the number of rooms in Bituś's house and the identifier of the room where Kapitan sleeps initially.

The following n−1n-1 describe corridors. Each of them contains two integers u_iu\_i, v_iv\_i (1≤u_i,v_i≤n1 \leq u\_i, v\_i \leq n, u_i≠v_iu\_i \neq v\_i) signifying that the rooms u_iu\_i and v_iv\_i are connected. You can assume that you can reach every room from any other.

The next line contains the number of rooms mm (1≤m≤5,000,0001 \leq m \leq 5\\,000\\,000) visited by Roomba during the cleaning session.

The last line of the test case contains a sequence of mm integers a_ia\_i (1≤a_i≤n1 \leq a\_i \leq n) -- the rooms visited (in this order) by Roomba. Every two subsequent rooms are connected with a corridor; moreover, assume that a_1≠ca\_1 \neq c.

The sum of values of n+mn + m over all test cases does not exceed 12,000,00012\\,000\\,000.

출력

For every test case print one real number ee -- the expected number of times Roomba entered a room with Kapitan inside. Your answer will be considered correct if its absolute or relative error does not exceed 10−510^{-5}. Namely, if your answer is aa, and the correct value is bb, then your answer will be accepted if ∣a−b∣max⁡(1,b)≤10−5\frac{|a-b|}{\max(1, b)} \leq 10^{-5}.

예제1

  1. 예제 1

    입력
    1
    4 2
    1 2
    2 3
    4 2
    4
    1 2 3 2
    
    예상 출력
    1.666666666666667