#P15619. [ICPC 2022 Jakarta R] City Hall
[ICPC 2022 Jakarta R] City Hall
题目描述
You are the mayor of ICPC City. The city has intersections, numbered from to , where intersection has an altitude of . Your house is at intersection , while the city hall is at intersection .
There are two-way roads, numbered from to , that connect the intersections. Road directly connects intersections and . 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 and . The energy that you spend to traverse that road is . 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 integers (; ; ; ). The next line contains integers () representing the altitude of intersection .
Each of the next lines contains integers () representing the intersections directly connected by road . 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 .
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 to . Then, cycling route requires a total energy of .
Explanation for the sample input/output #2
To get the minimum total required energy, you can choose either intersection or intersection and change its altitude to .
Explanation for the sample input/output #3
The cycling route requires a total energy of as all its intersections are at the same height. Changing any intersection's height will not decrease the total energy required.