Holiday Roads

On a tree, each of M families picks one of the other N-1 cities uniformly and independently; find the expected number of roads used by every family.

Medium7TreeProbabilityDFSNo attempts yetTime limit2sMemory limit512 MB

Problem

A country has NN cities and N1N-1 roads. The cities are numbered 00 through N1N-1. Every road is bidirectional and joins two different cities.

A simple path is a sequence of two or more cities in which no city appears twice and consecutive cities are joined by a road. Every pair of cities in this country is joined by a simple path, so the road network is a tree.

MM families live in the country, numbered 00 through M1M-1. Each family lives in one city, and several families may live in the same city.

For the holidays every family picked one city to travel to. The chosen city differs from the city the family lives in, and each of the other N1N-1 cities is equally likely. The families choose independently. During the holidays each family travels along the simple path from the city it lives in to the city it chose.

Depending on what the families picked, some roads are travelled by every family. Let LL be the number of such roads. Write a program that computes the expected value of LL.

Input

The first line contains the number of cities NN and the number of families MM. (2N512 \le N \le 51, 1M501 \le M \le 50)

Each of the next N1N-1 lines contains the numbers of the two cities joined by a road. The given roads always form a tree.

The last line contains MM numbers, the city each family lives in.

Output

Print the expected value of LL on the first line, rounded to nine digits after the decimal point. Always print all nine digits. If the expected value is exactly 1.51.5, print 1.500000000.

The input is chosen so that the expected value never sits on a rounding boundary at the ninth decimal digit, so double precision arithmetic produces the same output.

Explanation

Suppose three cities are joined in the order 00, 11, 22, and a single family lives in city 00. With probability 12\frac{1}{2} the family picks city 11 and travels one road, and with probability 12\frac{1}{2} it picks city 22 and travels two roads. There is only one family, so the roads it travels are exactly the roads travelled by every family. The expected value is 12×1+12×2=1.5\frac{1}{2} \times 1 + \frac{1}{2} \times 2 = 1.5.

In the same country with two families that both live in city 00, both pick city 22 with probability 14\frac{1}{4}, and then L=2L = 2. In every other case L=1L = 1, so the expected value is 14×2+34×1=1.25\frac{1}{4} \times 2 + \frac{3}{4} \times 1 = 1.25.