#P10326. 自由(Freedom)
自由(Freedom)
Background
Completely abstract, the infinite “freedom” that is only allowed in mathematics.
“Light of freedom”, the knight of the unknown — Zhi Xiu. Even when facing infinite despair, he can turn it into infinite freedom.
Problem Description
Given a directed graph with nodes and edges, both nodes and edges have weights. It is guaranteed that for any two nodes , there is at most one edge from to .
A path is a node sequence , where for any , there is an edge from to (denote this edge as ). Define the edge weight of as the product of the weights of all , its node weight as the sum of the weights of all , and its length as . In particular, if , define its edge weight to be .
For two paths with lengths , and node sequences and respectively, they are defined to be the same if and only if and holds for all .
Given a positive integer , compute the sum of the edge weights of all distinct paths whose node weight is . The answer may be very large; output it modulo .
Input testdata download link: Link1, extraction code: 92ih;
Backup download link and instructions: Link2.
Input Format
The first line contains a positive integer , indicating the test point ID.
The second line contains three positive integers , with meanings as described above.
The third line contains positive integers , where is the weight of node .
The next lines each contain three positive integers , indicating that there is an edge from node to node with weight .
Output Format
Output one line with one integer, representing the answer.
0
3 5 12
2 4 6
2 3 5
1 2 3
3 1 7
3 2 11
1 1 2
155
Hint
[Sample Explanation]
In the sample, . The paths whose node weight is are:
(What is given are the node IDs on the path; in the sample, each node’s weight happens to be twice its ID.)
- , edge weight is .
- , edge weight is .
- , edge weight is .
- , edge weight is .
- , edge weight is .
- , edge weight is .
So the answer is .
[Data Information]
| Test Point ID | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| Test Point Name | W | K_1 | K_2 | K_3 | MP_1 | MP_2 | MP_3 | MP_4 | R | Finale |
| Score | ||||||||||
For all testdata, , , .
[Reminder]
Time is precious. Running code takes time, and your thinking also takes time. Fortunately, these two things can happen at the same time. Hopefully, within this limited time, you can do more and achieve a better score.
Translated by ChatGPT 5