#P1453. 城市环路

    ID: 445 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp图论环套树,基环树

城市环路

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 nn vertices and nn edges. The unique cycle is the ring road. For any two vertices on the cycle, there are exactly 22 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 ii has a foot traffic pip_i, and opening a shop at that vertex yields a profit of pi×kp_i \times k, where kk is a constant.

Find the maximum total profit Jim can earn.

Input Format

  • The first line contains an integer nn, the number of vertices in the city. The nn vertices are numbered 0n10 \sim n-1.
  • The second line contains nn integers. The (i+1)(i + 1)-th integer is pip_i, the foot traffic of vertex ii.
  • The next nn lines each contain two integers u,vu, v, indicating that there is a road between uu and vv.
  • The last line contains a real number, the constant kk.

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 20%20\% of the testdata, n100n \leq 100.
  • For another 20%20\% of the testdata, the number of vertices on the cycle does not exceed 20002000.
  • For 100%100\% of the testdata, 1n1051 \leq n \leq 10^5, 1pi1041 \leq p_i \leq 10^4, 0u,v<n0 \leq u, v < n, 0k1040 \leq k \leq 10^4, and kk has at most 66 digits after the decimal point.

Translated by ChatGPT 5