#P10717. 【MX-X1-T5】「KDOI-05」简单的树上问题
【MX-X1-T5】「KDOI-05」简单的树上问题
Background
Original problem link: https://oier.team/problems/X1E.
Problem Description
Xiao S has a tree with nodes. Each node has a light bulb.
Xiao S decides to perform flashing operations. When performing a flashing operation, he sends one flashing command to each light bulb using the computer host.
However, Xiao S's light bulbs are of poor quality, and only some of them can receive Xiao S's flashing command. Specifically, the light bulb on node has probability to receive Xiao S's -th flashing operation.
Fortunately, Xiao S's different light bulbs can pass information to each other. Specifically, if a light bulb lies on the shortest path in the tree between two light bulbs that have received the information, then this light bulb can also perform the flashing operation (of course, the light bulbs that received the information will perform the flashing operation).
Define the beauty of light bulb as , where is the set of operations that this light bulb performs.
Define the beauty of the whole tree as the product of the beauty of all light bulbs. Find the expected beauty of the whole tree, modulo .
Input Format
The first line contains two positive integers , representing the number of nodes of the tree and the number of operations.
The next lines each contain two positive integers , representing an edge of the tree.
The next lines each contain non-negative integers. The -th number in the -th line represents modulo .
The next lines each contain non-negative integers. The -th number in the -th line represents . You can understand it as: in , the -th binary bit (from low to high) of indicates whether operation is included.
Output Format
One line with one non-negative integer, representing the expected beauty of the whole tree modulo .
3 1
1 2
2 3
499122177 499122177 499122177
1 2
1 3
1 4
499122186
10 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
1 1 4 5
1 4 1 9
1 9 8 1
0 1 1 4
5 1 4 1
9 1 9 8
1 0 9 9
8 2 4 4
3 5 3 1
2 3 4 5
497209006
Hint
[Sample Explanation #1]
::cute-table
| Set of bulbs that receive information | Bulb beauty | Tree beauty |
|---|---|---|
Therefore, the expected beauty is , and modulo it equals .
[Constraints]
This problem uses bundled testdata.
::cute-table{tuack}
| Subtask ID | Score | Special property | ||
|---|---|---|---|---|
| None | ||||
| Edge connects nodes and | ||||
| or | ||||
| Edge connects nodes and | ||||
| None | ||||
For of the data: , , . It is guaranteed that the given graph is a tree, and all other input values are integers in .
Translated by ChatGPT 5