Expected Pruning
You are given a tree with n vertices, rooted at vertex 1.
The following process is repeated until the tree is empty. Let S be the set of vertices that still remain. Choose a vertex v uniformly at random from S, and delete the entire subtree of v (including v itself) from the remaining tree.
Let X be the number of vertices chosen during the process. Output the expected value of X.
It can be shown that the answer can be expressed as a rational number P/Q in lowest terms with Q coprime to 109+7. Output P⋅Q−1mod(109+7).
Input
The first line contains an integer n.
Each of the next n−1 lines contains two integers u and v, describing an undirected edge of the tree.
Vertices are numbered 1 through n. Vertex 1 is the root. If n=1, there are no edge lines.
Output
Print a single integer: the expected number of selections modulo 109+7.
Constraints
- 1≤n≤105
- 1≤u,v≤n
- The edges form a tree.
Example 1
3
1 2
2 3
833333341
Explanation
Root 1 has depth 0, vertex 2 has depth 1, and vertex 3 has depth 2. The expected number of selections is 1+1/2+1/3=11/6, and 11⋅6−1≡833333341(mod109+7).
These events are strongly dependent: if the root is chosen first, nothing else is ever chosen. Linearity still gives the correct expectation.
Example 2
4
1 2
1 3
1 4
500000006
Explanation
The root contributes 1, and each of the three leaves contributes 1/2, for a total of 5/2.
Example 3
1
1
Explanation
The single vertex is always chosen.
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.