Forest Game
Time limit4sMemory limit512 MB
Given a tree, nodes are removed in random order and each removal adds its component size to the score. Output the expected total times N! mod 1e9+7.
- Level
Hard8 of 10
- Topics
- Tree, Divide and conquer, Combinatorics
- Solved
- No attempts yet
Problem
Consider the following boring game about removing nodes from a forest. Initially, the forest contains only one tree with nodes, and your initial score is . The game then goes as follows:
- If the forest is empty, the game is finished. Otherwise, you choose one node from the current forest uniformly at random.
- Your score increases by the size of the tree which your chosen node belongs to.
- Remove your chosen node and all edges connected to this node. Then proceed to step 1.
Please calculate the expected value of your final score multiplied by , modulo .
Input
The first line of input contains one integer , the number of nodes in the initial tree.
Each of the following lines contains two integers and , meaning that node and node are connected by an edge in the given tree. The nodes are numbered from to .
Output
Output one number: the expected value of the final score of this game multiplied by , modulo .
Constraints
- The given graph is a tree.