Under construction

Still being built. Things may change

City Hall

Time limit2sMemory limit1024 MB

Summary
Given a weighted graph where edge cost is the squared altitude difference, find the minimum path energy from S to T after raising or lowering one vertex's altitude freely.
Level

Hard8 of 10

Topics
Shortest path, Graph, Dynamic programming, Math
Solved
No attempts yet

Problem

You are the mayor of ICPC City. The city has NN intersections, numbered from 1 to NN. Intersection ii has altitude HiH_i. Your house is at intersection SS, and the city hall is at intersection TT.

There are MM two-way roads, numbered from 1 to MM. Road ii directly connects intersections UiU_i and ViV_i. Each pair of intersections is directly connected by at most one road. Every intersection can be reached from every other intersection by traversing one or more roads.

Every morning you cycle from your house to the city hall. When you traverse a road connecting intersections uu and vv, the energy you spend is (Hu−Hv)2(H_u - H_v)^2. The total energy of a path is the sum of the energy spent on each road in that path.

As mayor, you may change the altitude of at most one intersection to any non-negative real number. Using this, you want to minimize the total energy needed to cycle from your house to the city hall.

Input

The first line contains four integers NN, MM, SS, TT (2≤N≤100,0002 \le N \le 100{,}000; N−1≤M≤min⁡(N(N−1)2,200,000)N-1 \le M \le \min(\frac{N(N-1)}{2}, 200{,}000); 1≤S,T≤N1 \le S, T \le N; S≠TS \ne T). The next line contains NN integers HiH_i (0≤Hi≤100,0000 \le H_i \le 100{,}000), the altitude of each intersection. Each of the next MM lines contains two integers UiU_i and ViV_i (1≤Ui<Vi≤N1 \le U_i < V_i \le N), the intersections joined by road ii. Each pair of intersections is joined by at most one road, and the roads connect all intersections.

Output

Output one real number on a single line: the minimum total energy. An answer is accepted if its absolute error is at most 10−610^{-6}.

Examples3

  1. Example 1

    Input
    5 6 1 3
    5 100 8 2 10
    1 2
    2 3
    2 5
    1 4
    4 5
    3 5
    
    Expected output
    4.500000
    
  2. Example 2

    Input
    5 5 1 5
    1 2 10 10 4
    1 2
    2 3
    2 4
    3 5
    4 5
    
    Expected output
    3.000000
    
  3. Example 3

    Input
    5 4 1 4
    8 8 8 8 100
    1 2
    2 3
    3 4
    4 5
    
    Expected output
    0.000000