Octopus
Time limit2sMemory limit512 MB
An octopus walks a graph starting with no protection, collects tools to raise its shield, and each visit to a predator location risks being eaten with probability max(0, p - h); find the route from s to t with the highest survival probability.
- Level
Medium7 of 10
- Topics
- Graph, Shortest path, Greedy, Implementation
- Solved
- No attempts yet
Problem
The octopus is one of the few animals seen using tools on purpose to get a job done. A well known video shows an octopus carrying two coconut half shells across the sea floor and hiding inside them when it feels threatened.
Hiding tools differ in quality. When portable hiding tools are scattered over the sea floor, a small detour to pick up a better one raises the chance of not being eaten. Write a program that plans the route with the highest survival probability.
You are given locations on the sea floor and the passages between them. Each location holds a predator, or a hiding tool, or neither. A predator has a detection skill , a real number between and . A hiding tool has a protective value , a real number between and . When an octopus using a tool of protective value stays at a location with a predator of skill , that predator eats it with probability .
The octopus starts at location carrying nothing, so its protective value starts at . It travels along passages and has to reach location . The rules are as follows.
- Whenever the octopus stays at a location, it faces the predator check of that location. The check also happens at the start location and at the target location , and it happens again every time the octopus passes the same location again.
- On reaching a location with a hiding tool, the octopus can pick that tool up. It keeps every tool it picks up, and when it holds several tools it uses the one with the largest protective value.
- The octopus can travel over the same passage and through the same location any number of times.
The checks are independent of each other. Find the largest probability that the octopus starts at and reaches alive.
Input
The first line contains the number of data sets , with . Then come data sets in the following form.
The first line of a data set contains four integers , , , . Here is the number of locations, is the number of passages, and are the start and target locations.
The next line contains real numbers , each between and . If , location holds a hiding tool of protective value . If , location holds a predator of detection skill . If , location holds neither a predator nor a hiding tool.
Each of the next lines describes one passage. Line contains two integers , with , meaning the octopus can travel directly from location to and from to . The same passage can appear more than once. There is always a way to get from to .
Output
For each data set, first print Data Set x: on a line of its own, where is the number of the data set counting from . On the next line print the largest probability that the octopus reaches location alive, rounded to four decimal places. Print exactly four digits after the decimal point.
Print one blank line after each data set.