Expected Pruning

View as PDF

Submit solution


Points: 100
Time limit: 2.0s
PyPy 3 4.0s
Python 3 4.0s
Memory limit: 250M

Problem type

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 10^9 + 7. Output P \cdot Q^{-1} \bmod (10^9 + 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 10^9 + 7.

Constraints

  • 1 \le n \le 10^5
  • 1 \le u, v \le n
  • The edges form a tree.

Example 1

Input
3
1 2
2 3
Output
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 \cdot 6^{-1} \equiv 833333341 \pmod{10^9 + 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

Input
4
1 2
1 3
1 4
Output
500000006
Explanation

The root contributes 1, and each of the three leaves contributes 1/2, for a total of 5/2.

Example 3

Input
1
Output
1
Explanation

The single vertex is always chosen.


Comments

There are no comments at the moment.