Safety Precautions

Time limit1sMemory limit128 MB

Summary
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 ii has a threshold ti≥0t_i \ge 0, meaning that it can only malfunction if at least tit_i of the components it depends on have already malfunctioned. Thus, components with ti=0t_i = 0 can malfunction on their own.

We can equip components with safety technology. For component ii the price of this technology is a real number pi≥0p_i \ge 0. If we pay the price and add the technology to component ii, 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 KK of data sets. This is followed by KK data sets, each of the following form.

The first line of each data set contains an integer nn (1≤n≤201 \le n \le 20), the number of components in the system. The component we want to protect is always component nn.

This is followed by nn lines, each describing one component. The first number in line ii is the threshold tit_i of component ii. The second number (a floating-point number) is the price pip_i for protecting the component. The remaining numbers in line ii are the indices of the (zero or more) other components that component ii depends on. All of them are strictly less than ii, 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 xx is its number. On the next line, output the minimum cost at which component nn can be completely protected from malfunction, rounded to two decimals. Output one blank line between consecutive data sets.

Examples3

  1. Example 1

    Input
    1
    7
    0 1754.0
    1 200.5 1
    1 313.1
    1 4817.2 2 3
    4 3122 1 2 3 4
    0 512.3 1 3 5
    1 71582 2 5 6
    
    Expected output
    Data Set 1:
    712.80
    
  2. Example 2

    Input
    1
    3
    0 10.00
    0 20.00
    2 1000.00 1 2
    
    Expected output
    Data Set 1:
    10.00
    
  3. Example 3

    Input
    2
    7
    0 1754.0
    1 200.5 1
    1 313.1
    1 4817.2 2 3
    4 3122 1 2 3 4
    0 512.3 1 3 5
    1 71582 2 5 6
    3
    0 10.00
    0 20.00
    2 1000.00 1 2
    
    Expected output
    Data Set 1:
    712.80
    
    Data Set 2:
    10.00