#P6834. [Cnoi2020] 梦原
[Cnoi2020] 梦原
Description
Unfortunately, this tree has not grown up yet, and it only has a root node .
Cirno only knows that this tree will have nodes, with fruits on them respectively, but she cannot know the shape of the tree.
However, the growth of the tree always follows some pattern.
For node , it will choose a node uniformly at random from to connect to, and become a child of that node.
Here, is a constant that Cirno has already measured.
To pick all the fruits, after the tree has grown, Cirno will use magic multiple times. Each time, she chooses a connected subgraph (a connected component) on the tree, and picks one fruit from every node in that connected component (it must be guaranteed that every node in the connected component has at least one fruit).
Obviously, Cirno will use the best strategy to minimize the number of times she uses magic.
Now, Cirno already knows , , and the number of fruits that will grow on each node. Please help her compute the expected value of the minimum number of magic uses. For simplicity, you only need to output the remainder of the answer modulo .
Input Format
The first line contains two integers and , as described above.
The second line contains integers, denoting .
Output Format
Output one line with one integer, denoting the answer.
3 2
2 1 3
499122180
10 1
580461319 261515299 384092031 741339597 746815717 566875585 354719606 821499852 330315651 349091676
553073655
10 9
497873025 114058764 159468194 207476408 138162972 678927661 223886159 325207554 470061543 658861685
180853894
Hint
Explanation of Sample 1.
There are two possible trees as follows (black is the node index, red is the number of fruits on the node):

The best plan is to use magic once on connected component and once on , and use it twice on , for a total of times.

The best plan is to use magic once on each of the connected components , , and , for a total of times.
So the answer is .
Constraints and Notes
For of the testdata, it is guaranteed that and .
Subtasks (This problem uses bundled tests.)
- Subtask 1 (): .
- Subtask 2 (): , .
- Subtask 3 (): .
- Subtask 4 (): .
- Subtask 5 (): No additional constraints.
Translated by ChatGPT 5
京公网安备 11011102002149号