#P4202. [NOI2008] 奥运物流

[NOI2008] 奥运物流

Description

The 2008 Beijing Olympic Games are about to open, and the whole country is preparing for this grand event. To hold the Games efficiently and successfully, it is essential to plan the logistics system.

The logistics system consists of several logistics base stations, numbered from 11 to nn. Each logistics base station ii has exactly one successor station SiS_i, and may have multiple predecessor stations. All goods at station ii that need to continue transportation will be sent to its successor station SiS_i. Obviously, a station cannot be its own successor. Station 11 is called the control station, and goods can be sent from any station to the control station. Note that the control station also has a successor station, so that circulation is possible when needed. In the logistics system, high reliability and low cost are the main design goals. For station ii, we define its “reliability” R(i)R(i) as follows: Suppose station ii has ww predecessor stations P1,P2,,PwP_1, P_2, \cdots, P_w, i.e., these stations take ii as their successor station, then the reliability R(i)R(i) of station ii satisfies:

R(i)=Ci+kj=1wR(Pj).R(i)=C_i+k \sum_{j=1}^{w}R(P_j).

Here CiC_i and kk are fixed positive real numbers, and kk is less than 11.

The overall system reliability is positively correlated with the reliability of the control station. Our goal is to modify the logistics system—i.e., change the successors of some stations—so that the reliability R(1)R(1) of the control station is as large as possible. Due to budget constraints, at most mm stations’ successors can be modified, and the successor of the control station cannot be modified. Therefore, the problem is: how to modify the successors of no more than mm stations to maximize the reliability R(1)R(1) of the control station.

Input Format

The first line contains two integers and a real number, n,m,kn, m, k. Here nn is the number of stations, mm is the maximum number of successor changes allowed, and kk is the constant in the reliability definition.

The second line contains nn integers, S1,S2SnS_1, S_2 \cdots S_n, the successor station index of each station.

The third line contains nn positive real numbers, C1,C2CnC_1, C_2 \cdots C_n, the constants in the reliability definition.

Output Format

Output a single real number: the maximum achievable R(1)R(1). Round to two decimal places.

4 1 0.5  
2 3 1 3 
10.0 10.0 10.0 10.0
30.00 

Hint

[Sample explanation] In the original logistics system (as shown in the left figure), the reliabilities of the 44 stations are 22.8571,21.4286,25.7143,1022.8571, 21.4286, 25.7143, 10 in order.

The optimal plan is to change the successor of station 22 to station 11.

Then the reliabilities of the 44 stations become 30,25,15,1030, 25, 15, 10 in order. The testdata is distributed as follows:

测试数据编号 nn mm
11 6\leq 6
22 12\leq 12
33 60\leq 60 00
44 11
55 n2n-2
6,7,8,9,106, 7, 8, 9, 10 60\leq 60

For all testdata, mn60m \leq n \leq 60, Ci106C_i \leq 10^6, 0.3k<10.3 \leq k < 1. Please use double-precision floating-point numbers; you do not need to worry about the error introduced.

Translated by ChatGPT 5