#P1453. 城市环路
城市环路
Description
A city is often divided into several zones, such as residential, commercial, and industrial.
City B is divided into two zones—the city center and the suburbs. Between these two zones lies a ring road encircling City B; the area inside the ring is the city center.
The whole city can be modeled as a connected unicyclic graph with vertices and edges. The unique cycle is the ring road. For any two vertices on the cycle, there are exactly simple paths between them. All other parts of the graph belong to the suburbs.
Jim wants to open shops in City B. However, the two endpoints of any edge cannot both have shops. Each vertex has a foot traffic , and opening a shop at that vertex yields a profit of , where is a constant.
Find the maximum total profit Jim can earn.
Input Format
- The first line contains an integer , the number of vertices in the city. The vertices are numbered .
- The second line contains integers. The -th integer is , the foot traffic of vertex .
- The next lines each contain two integers , indicating that there is a road between and .
- The last line contains a real number, the constant .
Output Format
Output one line containing a real number representing the answer, rounded to one decimal place.
4
1 2 1 5
0 1
0 2
1 2
1 3
2
12.0
Hint
Constraints
- For of the testdata, .
- For another of the testdata, the number of vertices on the cycle does not exceed .
- For of the testdata, , , , , and has at most digits after the decimal point.
Translated by ChatGPT 5
京公网安备 11011102002149号