Electric Car
Time limit1sMemory limit1024 MB
Find the minimum total time to drive from city 1 to city N, where each road costs 1 hour and L energy, and charging takes whole hours at rate c_i per city.
- Level
Hard8 of 10
- Topics
- Graph, Shortest path, Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Vytautas wants to visit his friend Vytis in his brand-new, shiny electric car. Both friends live in Bitland, which consists of cities numbered from to . Vytautas lives in city , and Vytis lives in city . The cities are connected by two-way roads.
Along the way, Vytautas may have to stop and charge the car. If city has a charging station, it charges kWh per hour. Vytautas always charges for a whole number of hours (this makes it easier to plan his time). The battery capacity is kWh, and the charge never exceeds . If the battery becomes full before the hour is over, Vytautas simply leaves the car plugged in until the hour ends.
Driving along any single road takes exactly hour and consumes kWh. Because the car is brand new, the battery is empty at the start of the trip.
What is the shortest time in which Vytautas can travel from city to city , given that every charging session must last a whole number of hours?
Input
The first line contains four integers:
- — the number of cities;
- — the number of roads;
- — the battery capacity of the car;
- — the amount of energy the car consumes to drive along one road (one hour).
The second line contains integers () — city can charge kWh per hour (if , there is no charging station in that city).
Each of the next lines describes a road by its two endpoint cities and ().
Output
Output a single integer — the minimum time needed to travel from city to city . Output if the trip is impossible.
Constraints
- there is at most one direct road between any two cities.