#P6813. 「MCOI-02」Glass 玻璃
「MCOI-02」Glass 玻璃
Description
First, a tree is given. Each node has pieces of glass, and each edge has a weight .
In each operation, Xiao S can choose two nodes . On the unique path from node to node , the edge sum is the sum of the weights of all edges on the path, i.e. . The node sum is the sum of the numbers of glass on all nodes on the path (including ), i.e. . Xiao S can obtain a score equal to the product of the edge sum and the node sum, i.e. .
Any two operations cannot be exactly the same, and and are considered two different operations.
However, sometimes the tree is too large, and Xiao S needs your help. He wants you to tell him: after operations, how many points can be obtained in total. The result may be very large; you only need to output the answer modulo .
Input Format
The first line contains an integer , denoting the number of nodes in the tree.
The second line contains integers, where the -th number denotes the number of glass at node .
The next lines each contain three numbers , indicating that there is a tree edge between nodes and with weight .
Output Format
Output one integer, the total score modulo .
5
1 2 1 2 1
1 5 1
1 2 2
2 3 1
2 4 2
256
Hint
Sample Explanation
For sample , the tree looks like this:

Constraints
This problem uses bundled testdata.
| Subtask ID | Special Property | Score | Time Limit | ||
|---|---|---|---|---|---|
| 1 | |||||
| 2 | |||||
| 3 | |||||
| 4 | There exists a node with degree | ||||
| 5 | The tree is a chain | ||||
| 6 | |||||
| 7 |
For of the data, and .
Notes
Minecraft OI Round 2 D
- Maker: Inf_Voltage
- Tester: tarjin
Translated by ChatGPT 5
京公网安备 11011102002149号