#P2483. 【模板】k 短路 / [SDOI2010] 魔法猪学院

    ID: 1497 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2010各省省选山东O2优化最短路K 短路

【模板】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 \ldots

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 \ldots well, iPig’s magic instructor isn’t that naive! This time, the instructor has brought many samples of element 11 and requires iPig to transform them one by one into element NN 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 \ldots 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 N,M,EN, M, E, representing the number of known elements (numbered from 11 to NN), the number of learned spells, and iPig’s total energy.

Then follow MM lines, each containing three numbers si,ti,eis_i, t_i, e_i, indicating a known spell that transforms element sis_i to element tit_i while consuming energy eie_i.

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 44 meaningful conversion processes:

141\to 4, consuming energy 1.51.5.

12141\to 2\to 1\to 4, consuming energy 4.54.5.

1341\to 3\to 4, consuming energy 4.54.5.

12341\to 2\to 3\to 4, consuming energy 4.54.5.

Clearly, at most 33 of these conversion processes can be completed (choose the first one, and any two of the remaining three), i.e., at most 33 samples can be converted.

If E=14.9E=14.9 is changed to E=15E=15, then all of the above processes can be completed, and the answer becomes 44.

Input Format

Output Format

Hint

Constraints

  • At least 10%10\% of the total score: N6N \leq 6, M15M \leq 15.
  • At least 20%20\% of the total score: N100N \leq 100, M300M \leq 300, E100E \leq 100, and EE and all eie_i are integers (they can be read as integer types directly).
  • For all testdata: 2N50002 \leq N \leq 5000, 1M2000001 \leq M \leq 200000, 1E1071 \leq E \leq 10^7, 1eiE1 \leq e_i \leq E, and EE and all eie_i are real numbers.

Data Update Log

  • 2010/xx/xx: Original testdata.
  • 2018/03/02:
    /user/9168
    of testdata](/discuss/35616).
  • 2018/04/20:
    /user/25188
    of testdata](/discuss/40205).
  • 2021/01/08:
    /user/215697
    ets of testdata](/discuss/291028).

Translated by ChatGPT 5