#P10422. [蓝桥杯 2023 国 A] 迷宫探险
[蓝桥杯 2023 国 A] 迷宫探险
Problem Description
Warrior Xiao Lan is preparing to explore the distant LQ maze and obtain the treasure inside. The maze can be seen as an undirected graph with vertices (numbered ) and edges. Each vertex has a monster, each monster has a certain attack power, and each edge has a weight representing the time Xiao Lan spends to traverse that edge.
To obtain the maze treasure, Xiao Lan needs to start from vertex and explore the map. When passing through a vertex, he may kill the monster there. Xiao Lan has a finishing move that guarantees defeating a monster in one hit. However, when Xiao Lan kills a monster, the monsters that are still alive on the vertices adjacent to the monster’s vertex will each attack Xiao Lan once (note: this does not include the monster being killed). Xiao Lan’s HP will be reduced by the corresponding attack power. Only after Xiao Lan has killed all monsters and reached vertex , with HP greater than at that time, can he obtain the maze treasure.
Note that Xiao Lan’s finishing move is very fast, so killing a monster can be considered to take no time. A monster disappears after being killed once. Only when Xiao Lan kills a monster will the monsters on adjacent vertices attack Xiao Lan once.
If Xiao Lan can obtain the maze treasure, output the minimum time required. Otherwise, output .
Input Format
The first line contains three integers , separated by a single space, representing the number of vertices, the number of undirected edges, and Xiao Lan’s initial HP.
The second line contains integers, separated by a single space. The -th integer represents the attack power of the monster on the vertex with id .
The next lines each contain three integers , indicating that there is an undirected edge of weight between vertices and .
Output Format
Output one line containing one integer as the answer. If Xiao Lan cannot obtain the maze treasure no matter what, output .
3 2 10
2 10 5
0 1 1
1 2 2
5
Hint
[Sample Explanation 1]
Xiao Lan starts at vertex . The next step is to move to vertex , costing time .
Killing the monster at vertex will cause attacks from the monsters at vertices and , reducing HP by , leaving HP.
Move to vertex , costing time , then kill the monster at vertex , and no attack is received.
Move to vertex , then continue to vertex , costing time . Now kill the monster at vertex , and no attack is received. After all kills, Xiao Lan has HP left, meeting the requirement. The total time cost is .
[Constraints and Assumptions for Test Cases]
For of the test cases, .
For all test cases, , , , , .
Translated by ChatGPT 5