Expected Pruning
View as PDFYou are given a tree with vertices, rooted at vertex
.
The following process is repeated until the tree is empty. Let be the set of vertices
that still remain. Choose a vertex
uniformly at random from
, and delete the entire
subtree of
(including
itself) from the remaining tree.
Let be the number of vertices chosen during the process. Output the expected value of
.
It can be shown that the answer can be expressed as a rational number in lowest
terms with
coprime to
. Output
.
Input
The first line contains an integer .
Each of the next lines contains two integers
and
, describing an undirected
edge of the tree.
Vertices are numbered through
. Vertex
is the root. If
, there are no
edge lines.
Output
Print a single integer: the expected number of selections modulo .
Constraints
- The edges form a tree.
Example 1
Input
3
1 2
2 3
Output
833333341
Explanation
Root has depth
, vertex
has depth
, and vertex
has depth
. The
expected number of selections is
, and
.
These events are strongly dependent: if the root is chosen first, nothing else is ever chosen. Linearity still gives the correct expectation.
Example 2
Input
4
1 2
1 3
1 4
Output
500000006
Explanation
The root contributes , and each of the three leaves contributes
, for a total of
.
Example 3
Input
1
Output
1
Explanation
The single vertex is always chosen.
Comments