#ABC237E. [ABC237E] Skiing

[ABC237E] Skiing

Score : 500500 points

Problem Statement

AtCoder Ski Area has NN open spaces called Space 11, Space 22, \ldots, Space NN. The altitude of Space ii is HiH_i. There are MM slopes that connect two spaces bidirectionally. The ii-th slope (1iM)(1 \leq i \leq M) connects Space UiU_i and Space ViV_i. It is possible to travel between any two spaces using some slopes.

Takahashi can only travel between spaces by using slopes. Each time he goes through a slope, his happiness changes. Specifically, when he goes from Space XX to Space YY by using the slope that directly connects them, his happiness changes as follows.

  • If the altitude of Space XX is strictly higher than that of Space YY, the happiness increases by their difference: HXHYH_X-H_Y.
  • If the altitude of Space XX is strictly lower than that of Space YY, the happiness decreases by their difference multiplied by 22: 2(HYHX)2(H_Y-H_X).
  • If the altitude of Space XX is equal to that of Space YY, the happiness does not change.

The happiness may be a negative value.

Initially, Takahashi is in Space 11, and his happiness is 00. Find his maximum possible happiness after going through any number of slopes (possibly zero), ending in any space.

Constraints

  • 2N2×1052 \leq N \leq 2\times 10^5
  • $N-1 \leq M \leq \min( 2\times 10^5,\frac{N(N-1)}{2})$
  • 0Hi1080 \leq H_i\leq 10^8 (1iN)(1 \leq i \leq N)
  • 1Ui<ViN1 \leq U_i < V_i \leq N (1iM)(1 \leq i \leq M)
  • (Ui,Vi)(Uj,Vj)(U_i,V_i) \neq (U_j, V_j) if iji \neq j.
  • All values in input are integers.
  • It is possible to travel between any two spaces using some slopes.

Input

Input is given from Standard Input in the following format:

NN MM

H1H_1 H2H_2 \ldots HNH_N

U1U_1 V1V_1

U2U_2 V2V_2

\vdots

UMU_M VMV_M

Output

Print the answer.

4 4
10 8 12 5
1 2
1 3
2 3
3 4
3

If Takahashi takes the route Space 11 \to Space 33 \to Space 44, his happiness changes as follows.

  • When going from Space 11 (altitude 1010) to Space 33 (altitude 1212), it decreases by 2×(1210)=42\times (12-10)=4 and becomes 04=40-4=-4.
  • When going from Space 33 (altitude 1212) to Space 44 (altitude 55), it increases by 125=712-5=7 and becomes 4+7=3-4+7=3.

If he ends the travel here, the final happiness will be 33, which is the maximum possible value.

2 1
0 10
1 2
0

His happiness is maximized by not moving at all.