Infinathlon
View as PDFThe MAPS Committee is looking to spice things up with the Pentathlon and introduce some more sports.
The "Infinathlon" is a new sporting event that has competitors running between different arenas, completing different sports, with the aim of reaching the final arena.
How this works is that each competitor starts off with 0 seconds on their timer, and whenever they are running between arenas, this timer decrements. If the timer ever goes below 0 seconds, then they are disqualified.
Within the arenas, competitors can do challenges from other sporting events to earn time on their clock, allowing them to travel between arenas. Depending on the strength of their performance, for every second they add to their clock, they'll accrue a certain amount of penalty points. Finally, the clock also maxes out at a certain time-limit, stopping competitors from filling out their clock at a single event, and encouraging competitors to use multiple arenas on their journey.
The winner of the competition is not the fastest competitor, but the one that accrues the least penalty points.
You're trying to help out your friend Eric. Eric's been given the map layout for the Infinathlon ahead of time, and Eric knows his strengths and weaknesses, in particular, he knows:
- How long it will take him to run between arenas, in exact seconds, and
- For every arena, how many penalty points he will get per second added to his timer there.
Eric would like to know the minimum number of penalty points to get him from arena (with 0s on the clock) to arena
.
Input
Input will begin with 5 integers:
- The number of arenas
(
)
- The number of pathways between arenas
(
)
- The maximum number of seconds you can have on your clock (
)
- The starting arena
(
)
- The ending arena
(
)
The next line will contain integers
(
), representing the amount of penalty points you know you'll get per second earned in each arena, from
to
.
lines will follow, detailing the paths between arenas. Note that these paths are directed.
Each line will contain 3 integers ,
and
, representing that travelling from arena
to arena
will take exactly
seconds (
,
).
There are no self loops (), and no directed edge appears in the input twice.
Output
Output a single integer, representing the minimal penalty required to get from arena (Starting with 0s) to arena
.
If it is impossible to reach arena , then instead output the string
Unreachable
Example 1
Input
6 9 30 1 6
2 100 1 3 3 5
1 2 25
1 3 32
2 3 5
3 4 28
4 3 10
4 2 5
2 5 20
5 1 6
5 6 5
Output
174
Explanation
The sample input represents the following field:

Which can be solved in 174 penalty by:
- Immediately maxing out 30s on the clock at Node 1: Shooting (+60 penalty)
- Running from Shooting(1) to Fencing(2), and Fencing(2) to Weightlifting(3)
- Maxing out again at Weightlifting (+30 penalty)
- Running to Breakdancing(4)
- Earning 23s at Breakdancing(4) (+69 penalty)
- Running to Fencing(2) then Diving(5)
- Earning 5s at Diving(5) (+15 penalty)
- Running to Trampoline Gymnastics(6), the goal.

Comments