Caves
Time limit2sMemory limit256 MB
Given cave tunnels and treasure probabilities, find the minimum expected time to reach the treasure by walking the probe or paying t to insert a new one.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Bit manipulation, Shortest path, Graph
- Solved
- No attempts yet
Problem
Sophie is a treasure seeker. She is looking for a treasure hidden in a system of caves, numbered from to . The cave system contains exactly one treasure, in one of the caves. Sophie used a georadar, which did not reveal where the treasure is, but gave her a probability for each cave that the treasure is in that cave.
Sophie continues the search with a precise remote probe. When the probe enters a cave, it immediately finds out whether that cave contains the treasure. The probe starts in cave , and it is known that this cave does not contain the treasure. Sophie knows which pairs of caves are connected by bidirectional tunnels that the probe can traverse. Each traversal takes the probe one minute. The probe may not be able to reach every cave, even in many steps.
Instead of traversing a tunnel, Sophie can abandon the probe and insert a new one, which takes minutes. The old probe is then lost, and Sophie can no longer use it. A new probe is imprecise: it lands in each of the caves with probability . Sophie immediately learns where the probe has landed. Sophie has infinitely many probes.
Help Sophie find the treasure quickly. Given the size of the cave system, the tunnels, the insertion time , and the probability distribution of the treasure, compute the smallest expected time over all of Sophie's strategies. Finding the treasure means reaching the treasure cave with a probe.
Input
The first line contains three space-separated integers , , (, , ). They denote the number of caves, the number of tunnels, and the time needed to insert a new probe.
The second line contains space-separated real numbers (, , ). The number is the probability that the treasure is in cave . These values have two decimal digits of precision.
Each of the next lines contains two space-separated integers , (, ), describing a tunnel between caves and that the probe can traverse in either direction. All tunnels are distinct.
Output
Print one real number, the minimum possible expected time of finding the treasure. The answer is accepted if its absolute or relative error is at most .
Hint

In sample 1, Sophie first moves the probe to cave , then to cave . With probability , she finds the treasure at time . Otherwise, she inserts new probes until one lands in cave . The expected number of insertions is , so the expected total time in this case is . On average, Sophie finds the treasure in seconds. After minutes, Sophie already knows where the treasure is, but she still needs a probe to reach it.