#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 NN vertices (numbered 0N10\sim N-1) and MM edges. Each vertex has a monster, each monster has a certain attack power, and each edge has a weight ww representing the time Xiao Lan spends to traverse that edge.

To obtain the maze treasure, Xiao Lan needs to start from vertex 00 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 N1N-1, with HP greater than 00 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 1-1.

Input Format

The first line contains three integers N,M,HPN, M, HP, 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 NN integers, separated by a single space. The i(0iN1)i(0\le i\le N-1)-th integer represents the attack power of the monster on the vertex with id ii.

The next MM lines each contain three integers u,v,wu, v, w, indicating that there is an undirected edge of weight ww between vertices uu and vv.

Output Format

Output one line containing one integer as the answer. If Xiao Lan cannot obtain the maze treasure no matter what, output 1-1.

3 2 10
2 10 5
0 1 1
1 2 2

5

Hint

[Sample Explanation 1]

Xiao Lan starts at vertex 00. The next step is to move to vertex 11, costing time 11.

Killing the monster at vertex 11 will cause attacks from the monsters at vertices 00 and 22, reducing HP by 77, leaving 33 HP.

Move to vertex 00, costing time 11, then kill the monster at vertex 00, and no attack is received.

Move to vertex 11, then continue to vertex 22, costing time 33. Now kill the monster at vertex 22, and no attack is received. After all kills, Xiao Lan has 33 HP left, meeting the requirement. The total time cost is 55.

[Constraints and Assumptions for Test Cases]

For 40%40\% of the test cases, 1N101\le N\le 10.
For all test cases, 1N151\le N\le 15, 1MN21\le M\le N^2, 1HP1001\le HP\le 100, 1monster attack power101\le \text{monster attack power} \le 10, 1w101\le w\le 10.

Translated by ChatGPT 5