Problem B
Eating Everything Efficiently

Margriet A. is in pizza heaven! She has bought a one-day
access pass to Pizza World. Pizza World is a food festival,
where all stands have their own special type of pizza. Margriet
would really like to try many different types of pizza, but she
thinks that she can only eat two pizzas in total. Therefore,
she has come up with a cunning plan: at each stall she visits
she decides whether she wants to buy this pizza or not. At the
first stall where she decides to make a purchase, she buys and
eats exactly one pizza. At the second one, she buys and eats
half a pizza, and at the third she eats one quarter of a pizza,
etc. …Therefore, at the
In order to ensure that the flow of people in the park is
adequate, the pizza stalls are connected by one-way paths, and
to make sure that everyone eventually leaves the festival, it
is impossible to visit a pizza stall more than once. However,
every stall is reachable from the stall at the entrance, which
is the stall with number
Of course, Margriet has her own taste: she likes some pizzas more than others. Eating pizza from a stall gives her a certain amount of satisfaction which is equal to Margriet’s personal stall satisfaction number multiplied by the fraction of a whole pizza she eats there. Her total satisfaction is the sum of satisfactions of every stall she visits. Can you help Margriet plot a route between the pizza stalls that satisfies her the most?
Input
-
The first line has two integers,
and , the number of pizza stalls and the number of one way connections. -
The second line has
integers , where each , the amount of satisfaction Margriet gets from eating one pizza at stall . -
The next
lines each contain integers, and , indicating a one way path from stall to stall . No connection appears twice in the input.
Output
-
Print the maximal amount of satisfaction Margriet can reach at the pizza festival. Your answer is considered correct if it has absolute or relative error of at most
.
Sample Input 1 | Sample Output 1 |
---|---|
5 5 1 4 6 2 100 0 1 1 2 0 3 2 4 3 4 |
100 |
Sample Input 2 | Sample Output 2 |
---|---|
3 2 1 0 1 0 1 1 2 |
1.5 |
Sample Input 3 | Sample Output 3 |
---|---|
3 2 3 2 1 0 1 1 2 |
4.25 |