#P7247. 教材运送
教材运送
Description
The teaching building of Modu High School is a tree with nodes. Node corresponds to classroom , with students. Each undirected edge is described as , meaning it connects classrooms and , and the stairs between them have a vertical height difference of .
At the beginning of the new semester, textbooks need to be distributed to students, but a failure in the teleportation system caused the textbooks to be scattered across different classrooms. When Tianyi is in classroom , she will randomly pick up textbooks belonging to classroom , and deliver them to classroom along the unique simple path between classrooms and . Suppose the height differences of the stairs Tianyi walks through are , and the weight of each textbook is . Then the absolute value of the work done by Tianyi’s lifting force during this delivery (taking positive work for going up and the absolute value of negative work for going down) is defined as . In other words, the cost of one delivery is the product of the endpoint node weight and the sum of edge weights along the path.
Initially, Tianyi is in classroom , but she does not know the way, so Ayane will guide Tianyi to deliver textbooks such that Tianyi visits every classroom at least once. Before achieving this goal, what is the expected total absolute work done by Tianyi’s lifting force, in ?
Since the answer may be a decimal, to avoid precision loss, output the value of the answer modulo .
Simplified statement
Given an unrooted tree with nodes, with node weights and edge weights. Let the current position be (initially ). Each time, randomly choose a target node among the nodes, pay a cost of (“sum of edge weights on the simple path from to ”) (“node weight of ”), mark node (marking can repeat), and set . Find the expected total cost when every node has been marked at least once (node is marked from the start). Output the answer modulo .
Input Format
The first line contains an integer , as described above.
The second line contains integers, representing the number of students in each classroom.
The next lines each contain three integers , meaning there is a staircase with vertical height difference between classrooms and .
Output Format
One line with one integer, representing the answer modulo .
3
1 2 3
1 2 1
2 3 1
332748127
5
2 3 4 2 5
1 2 3
2 4 2
2 5 5
1 3 3
615584181
2
1 2
1 2 2
4
Hint
Constraints and notes
This problem uses bundled testdata.
For of the testdata, , , , and it is guaranteed that .
| Subtask | Points | Special constraints | |
|---|---|---|---|
| 1 | 5 | / | |
| 2 | 10 | ||
| 3 | |||
| 4 | 25 | ||
| 5 | / | For , . | |
| 6 | 10 | For every edge, , i.e. the tree is a chain. | |
| 7 | 35 | / | |
Translated by ChatGPT 5
京公网安备 11011102002149号