Safety Precautions
Time limit1sMemory limit128 MB
Given a DAG where each node fails only after at least t dependencies have failed, choose nodes to protect so node n never fails, minimizing protection cost.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Graph, DFS, Bit manipulation
- Solved
- No attempts yet
Problem
Explosions of oil rigs -- and, for that matter, other factories and production systems -- are meant to be prevented by multi-level safety systems. For instance, a pipe leak may not be a problem if another pipe around it can catch the oil. High pressure will not cause major damage if there are relief valves, and so on. A large share of good engineering is building safety into systems naturally. To encourage such good engineering, governments tend to prescribe safety regulations for building deep-water oil rigs. Unfortunately, for such regulations to work they must also be enforced, which has not really been the case over the last few years.
A simplified way to model the safety of a system such as an oil well is the following. Components may depend on other components for their operation, and they can malfunction. Some may malfunction on their own; others malfunction only if some of the components they depend on have already malfunctioned. For simplicity we assume that there are never cycles in the component dependencies. Each component has a threshold , meaning that it can only malfunction if at least of the components it depends on have already malfunctioned. Thus, components with can malfunction on their own.
We can equip components with safety technology. For component the price of this technology is a real number . If we pay the price and add the technology to component , it will never malfunction, even if all of the other components it depends on do. Our goal is to protect one designated component from malfunctioning; imagine that this component corresponds to the oil rig exploding. Of course, we want to do so at the lowest possible total cost.
Input
The first line contains the number of data sets. This is followed by data sets, each of the following form.
The first line of each data set contains an integer (), the number of components in the system. The component we want to protect is always component .
This is followed by lines, each describing one component. The first number in line is the threshold of component . The second number (a floating-point number) is the price for protecting the component. The remaining numbers in line are the indices of the (zero or more) other components that component depends on. All of them are strictly less than , which also ensures that there are no cycles in the dependencies.
Output
For each data set, output Data Set x: on a line by itself, where is its number. On the next line, output the minimum cost at which component can be completely protected from malfunction, rounded to two decimals. Output one blank line between consecutive data sets.