This page is still under construction.

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

Routing a Marathon Race

Time limit3sMemory limit256 MB

Summary
Find a simple path from junction 1 to junction n that minimizes the total personnel cost of the junctions on the path and their direct neighbors.
Level

Hard8 of 10

Topics
Backtracking, Graph, DFS, Brute force
Solved
No attempts yet

Problem

As a member of the Ibaraki Committee of Physical Competitions, you plan the route of a marathon event held in the City of Tsukuba. A great number of runners, from beginners to experts, take part.

You have a city map that lists every street segment suited for the event and every junction on those segments. The race starts at the junction in front of Tsukuba High and ends at the junction in front of City Hall. Both are marked on the map.

To avoid congestion and confusion of runners of divergent skills, the route does not visit the same junction twice. A street segment can be run in either direction, but it goes into the route at most once. The event is about recreation and the health of citizens, so time records do not matter and you can decide the distance of the route freely.

Personnel have to be stationed at every junction on the route. Junctions connected directly by a street segment to a junction on the route also need personnel, so that casual traffic does not interfere with the race. Junction kk needs ckc_k personnel, and that number is the same whether the junction is on the route or next to a junction on the route. Different junctions need different numbers depending on their sizes and shapes, and the map gives those numbers. No junction is staffed twice.

The municipal authorities want to reduce the personnel expense of events of this kind. Write a program that plans a route requiring the fewest personnel and prints that number.

Input

The input consists of a single test case representing a summary city map, formatted as follows.

n m
c1
.
.
.
cn
i1 j1
.
.
.
im jm

The first line has two positive integers nn and mm. Here nn is the number of junctions in the map (2≤n≤402 \le n \le 40), and mm is the number of street segments connecting adjacent junctions. Junctions are identified by integers 11 through nn.

Then come nn lines giving the numbers of personnel required. The kk-th of them, an integer ckc_k, is the number of personnel required for junction kk (1≤ck≤1001 \le c_k \le 100).

The remaining mm lines list street segments between junctions. The two integers iki_k and jkj_k on each line represent a segment connecting junctions iki_k and jkj_k (ik≠jki_k \ne j_k). At most one street segment connects the same pair of junctions.

The race starts at junction 11 and the goal is junction nn. At least one route connects the start and the goal.

Output

Print one integer, the minimum possible number of personnel required.

Note

The figure shows the lowest-cost route for the first example input. The arrows indicate the route and the circles painted gray are junctions requiring personnel. The minimum number of required personnel is 17 in that case.

Examples3

  1. Example 1

    Input
    6 6
    3
    1
    9
    4
    3
    6
    1 2
    1 4
    2 6
    5 4
    6 5
    3 2
    
    Expected output
    17
    
  2. Example 2

    Input
    2 1
    7
    5
    1 2
    
    Expected output
    12
    
  3. Example 3

    Input
    7 7
    1
    1
    1
    1
    1
    100
    1
    1 2
    1 3
    2 6
    2 7
    3 4
    4 5
    5 7
    
    Expected output
    6