National Olympiad in Informatics, China, 2008
The Beijing 2008 Olympics is about to open, and the entire nation is
preparing for this grand event. To maximize efficiency when setting up
and hosting a successful Olympics, the planning of logistics is
essential.
The logistics system consists of
total stations numbered from
to
. Each station
has exactly one successor station
,
but can have many predecessor stations. Station
needs to
continuously deliver materials to successor station
. Obviously,
a station's successor station cannot be itself. Station
is known as
the control station, and any other station can deliver materials to
it. Note that the control station also has its own successor station to
permit the flow of materials when necessary. In the design of this
logistics system, high reliability and low costs are the main
objectives. So for station
, we can define its "reliability"
as follows:
Let station
have
predecessor stations
,
meaning that
is the sole successor of each of these
stations. Then, station
's reliability
is given by the
following formula:

where
and
are positive real constants, and
.
The reliability of the entire logistics system is directly based on
the reliability of the control station. Our goal is to maximize the
control station's reliability value
by modifying the successor
stations of some other stations. However, our budget is also limited –
we may only modify at most
successor stations. Furthermore, the
successor of the control station cannot be modified. Thus, the overall
problem we face is to maximize the control station's reliability
by changing the successors of no more than
stations.
Input Specification
The first line of input contains two integers
and
, followed by
one real number
.
represents the number of stations,
represents the maximum number of successor stations that may be changed,
and
is the constant used in the definition of the reliability
formula.
The second line contains
integers
,
representing the successor stations of each station.
The third line contains
positive real numbers
,
representing the constant values used in the reliability formula.
Output Specification
The output should contain one real number, the maximum possible value of
rounded and displayed to
decimal places.
Sample Input
Copy
4 1 0.5
2 3 1 3
10.0 10.0 10.0 10.0
Sample Output
Copy
30.00
Explanation
The original logistics system is depicted in the left figure below.
There are
stations with reliability values
,
,
,
and
, respectively.
The best solution is to modify the successor of station
to station
, as
depicted in the right figure above. The new reliability values of the
stations are
,
,
, and
, respectively.
Constraints
Test Case |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
to  |
 |
 |
For all of the test cases,
,
,
and
. Please use double precision real numbers; there is no
need to worry about their precision.
Problem translated to English by Alex.
Comments