atcoder#ABC149F. [ABC149F] Surrounded Nodes
[ABC149F] Surrounded Nodes
Score : points
Problem Statement
Given is a tree with vertices. The -th edge connects Vertex and ().
Now, each vertex is painted black with probability and white with probability , which is chosen independently from other vertices. Then, let be the smallest subtree (connected subgraph) of containing all the vertices painted black. (If no vertex is painted black, is the empty graph.)
Let the holeyness of be the number of white vertices contained in . Find the expected holeyness of .
Since the answer is a rational number, we ask you to print it , as described in Notes.
Notes
When you print a rational number, first write it as a fraction , where are integers, and is not divisible by (under the constraints of the problem, such representation is always possible).
Then, you need to print the only integer between and , inclusive, that satisfies .
Constraints
- The given graph is a tree.
Input
Input is given from Standard Input in the following format:
Output
Print the expected holeyness of , .
3
1 2
2 3
125000001
If the vertices are painted black, white, black, respectively, the holeyness of is .
Otherwise, the holeyness is , so the expected holeyness is .
Since , we should print .
4
1 2
2 3
3 4
375000003
The expected holeyness is .
Since , we should print .
4
1 2
1 3
1 4
250000002
The expected holeyness is .
7
4 7
3 1
2 6
5 2
7 1
2 7
570312505