#P2483. 【模板】k 短路 / [SDOI2010] 魔法猪学院
【模板】k 短路 / [SDOI2010] 魔法猪学院
Description
iPig has arrived at the legendary Magic Pig Academy for a two-month training program. After one week of theory and one week of basic magic, iPig has learned a lot about the fundamentals of the pig world: as everyone knows, the world is made of elements; elements can be transformed into one another; energy is conserved
Today iPig is taking a tricky test. From previous learning, iPig already knows many kinds of elements and has learned spells that can transform these elements, each consuming some energy. As a top student from PKU, using the least energy to transform one element into another well, iPig’s magic instructor isn’t that naive! This time, the instructor has brought many samples of element and requires iPig to transform them one by one into element using learned spells. To make it harder, each sample must follow a different conversion process. This seemingly difficult task is actually not a challenge for iPig, because he has a solid backup you!
Note that there can be multiple spells for transforming between two elements, and transformations are one-way. During a conversion, an element (including the starting element) may be visited multiple times, but once the target element is reached, that sample’s conversion process ends. iPig’s total energy is limited, so the maximum number of samples he can convert is finite. See the example for details.
Input Format
The first line contains three numbers , representing the number of known elements (numbered from to ), the number of learned spells, and iPig’s total energy.
Then follow lines, each containing three numbers , indicating a known spell that transforms element to element while consuming energy .
Output Format
Output a single integer: the maximum number of distinct conversion processes that can be completed. The input guarantees that at least one way exists.
4 6 14.9
1 2 1.5
2 1 1.5
1 3 3
2 3 1.5
3 4 1.5
1 4 1.5
3
Hint
There are meaningful conversion processes:
, consuming energy .
, consuming energy .
, consuming energy .
, consuming energy .
Clearly, at most of these conversion processes can be completed (choose the first one, and any two of the remaining three), i.e., at most samples can be converted.
If is changed to , then all of the above processes can be completed, and the answer becomes .
Input Format
Output Format
Hint
Constraints
- At least of the total score: , .
- At least of the total score: , , , and and all are integers (they can be read as integer types directly).
- For all testdata: , , , , and and all are real numbers.
Data Update Log
- 2010/xx/xx: Original testdata.
- 2018/03/02: /user/9168of testdata](/discuss/35616).
- 2018/04/20: /user/25188of testdata](/discuss/40205).
- 2021/01/08: /user/215697ets of testdata](/discuss/291028).
Translated by ChatGPT 5
京公网安备 11011102002149号