This page is still under construction.

Parts of this page are still being built. What you see may change.

Electric Car

Time limit1sMemory limit1024 MB

Summary
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 NN cities numbered from 11 to NN. Vytautas lives in city 11, and Vytis lives in city NN. The cities are connected by MM two-way roads.

Along the way, Vytautas may have to stop and charge the car. If city ii has a charging station, it charges cic_i kWh per hour. Vytautas always charges for a whole number of hours (this makes it easier to plan his time). The battery capacity is KK kWh, and the charge never exceeds KK. 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 11 hour and consumes LL 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 11 to city NN, given that every charging session must last a whole number of hours?

Input

The first line contains four integers:

  • NN — the number of cities;
  • MM — the number of roads;
  • KK — the battery capacity of the car;
  • LL — the amount of energy the car consumes to drive along one road (one hour).

The second line contains NN integers cic_i (0≤ci≤K0 \le c_i \le K) — city ii can charge cic_i kWh per hour (if ci=0c_i = 0, there is no charging station in that city).

Each of the next MM lines describes a road by its two endpoint cities aia_i and bib_i (1≤ai,bi≤N1 \le a_i, b_i \le N).

Output

Output a single integer — the minimum time needed to travel from city 11 to city NN. Output −1-1 if the trip is impossible.

Constraints

  • 2≤N≤100 0002 \le N \le 100\,000
  • 1≤M≤100 0001 \le M \le 100\,000
  • 1≤K,L≤1001 \le K, L \le 100
  • ai≠bia_i \ne b_i
  • there is at most one direct road between any two cities.

Examples3

  1. Example 1

    Input
    5 5 13 11
    7 10 1 10 2
    1 2
    1 3
    2 4
    3 5
    4 5
    
    Expected output
    7
    
  2. Example 2

    Input
    2 1 10 5
    5 0
    1 2
    
    Expected output
    2
    
  3. Example 3

    Input
    2 1 10 5
    0 5
    1 2
    
    Expected output
    -1