City Hall

시간 제한2초메모리 제한1024 MB

요약
간선 비용이 두 교차점 고도의 제곱 차이인 그래프에서 교차점 하나의 고도를 음이 아닌 실수로 바꿀 수 있을 때 S에서 T까지 가는 최소 비용을 구한다.
난이도

어려움10점 중 8점

유형
최단 경로, 그래프, 수학, 그리디
정답자
아직 제출이 없습니다

문제

You are the mayor of ICPC City. The city has NN intersections, numbered from 11 to NN, where intersection ii has an altitude of H_iH\_i. Your house is at intersection SS, while the city hall is at intersection TT.

There are MM two-way roads, numbered from 11 to MM, that connect the intersections. Road ii directly connects intersections U_iU\_i and V_iV\_i. Each pair of intersections can only be directly connected by at most one road. The roads connect such that each intersection can be visited from any other intersections by traversing one or more roads.

Every morning, you cycle from your house to the city hall. Suppose that you are traversing a road that directly connects intersections uu and vv. The energy that you spend to traverse that road is (H_u−H_v)2(H\_u - H\_v)^2. The total energy required for a path is the sum of energy that is spent traversing each road in that path.

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

입력

Input begins with 44 integers NN MM SS TT (2≤N≤100,0002 ≤ N ≤ 100\\, 000; N−1≤M≤min⁡(N(N−1)2,200,000)N -1 ≤ M ≤ \min(\frac{N(N-1)}{2}, 200\\, 000); 1≤S,T≤N1 ≤ S, T ≤ N; S≠TS \ne T). The next line contains NN integers H_iH\_i (0≤H_i≤100,0000 ≤ H\_i ≤ 100\\, 000) representing the altitude of intersection ii.

Each of the next MM lines contains 22 integers U_iU\_i V_iV\_i (1≤U_i<V_i≤N1 ≤ U\_i < V\_i ≤ N) representing the intersections directly connected by road ii. Each pair of intersections can only be directly connected by at most one road. Furthermore, the roads connect such that each intersection can be visited from any other intersections by traversing one or more roads.

출력

Output a real number in a single line representing the minimum total energy required. Your answer is considered correct if its absolute error does not exceed 10−610^{-6}.

예제3

  1. 예제 1

    입력
    5 6 1 3
    5 100 8 2 10
    1 2
    2 3
    2 5
    1 4
    4 5
    3 5
    
    예상 출력
    4.500000
    
  2. 예제 2

    입력
    5 5 1 5
    1 2 10 10 4
    1 2
    2 3
    2 4
    3 5
    4 5
    
    예상 출력
    3.000000
    
  3. 예제 3

    입력
    5 4 1 4
    8 8 8 8 100
    1 2
    2 3
    3 4
    4 5
    
    예상 출력
    0.000000