#P15619. [ICPC 2022 Jakarta R] City Hall

    ID: 15535 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2022Special Judge最短路凸包ICPC李超线段树

[ICPC 2022 Jakarta R] City Hall

题目描述

You are the mayor of ICPC City. The city has NN intersections, numbered from 11 to NN, where intersection ii has an altitude of HiH_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 UiU_i and ViV_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 (HuHv)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 (2N1000002 \leq N \leq 100\,000; N1Mmin(N(N1)2,200000)N - 1 \leq M \leq \min(\frac{N(N-1)}{2}, 200\,000); 1S,TN1 \leq S, T \leq N; STS \neq T). The next line contains NN integers HiH_i (0Hi1000000 \leq H_i \leq 100\,000) representing the altitude of intersection ii.

Each of the next MM lines contains 22 integers UiU_i ViV_i (1Ui<ViN1 \leq U_i < V_i \leq 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 10610^{-6}.

5 6 1 3
5 100 8 2 10
1 2
2 3
2 5
1 4
4 5
3 5
4.500000
5 5 1 5
1 2 10 10 4
1 2
2 3
2 4
3 5
4 5
3.000000
5 4 1 4
8 8 8 8 100
1 2
2 3
3 4
4 5
0.000000

提示

Explanation for the sample input/output #1

To get the minimum total required energy, you should change the altitude of intersection 22 to 6.56.5. Then, cycling route 1231 \rightarrow 2 \rightarrow 3 requires a total energy of (56.5)2+(86.5)2=4.5(5 - 6.5)^2 + (8 - 6.5)^2 = 4.5.

Explanation for the sample input/output #2

To get the minimum total required energy, you can choose either intersection 33 or intersection 44 and change its altitude to 33.

Explanation for the sample input/output #3

The cycling route 12341 \rightarrow 2 \rightarrow 3 \rightarrow 4 requires a total energy of 00 as all its intersections are at the same height. Changing any intersection's height will not decrease the total energy required.