Under construction

Still being built. Things may change

Heracles and the Stables of Augeas

Time limit1sMemory limit256 MB

Summary
Pick rivers whose water totals at least W so the sum of straight-line digging distances from the stable is smallest.
Level

Medium5 of 10

Topics
Dynamic programming, Geometry
Solved
No attempts yet

Problem

Heracles faced twelve labors. The fifth was not as dramatic as slaying a giant serpent: he had to clean the stables of Augeas, home to more than 1000 cattle and untouched for 30 years, in a single day.

Instead of shoveling by hand, he diverted nearby rivers through the stables. You are given several rivers, each described as a polyline with a water supply. Choose which rivers to divert so the stables receive at least WW units of water while minimizing total digging distance.

For each chosen river, Heracles digs one straight canal from the stable to the closest point on that river. Canals may cross each other or other rivers, and he cannot merge canals to save work.

Input

The first line contains an integer KK, the number of data sets. Each data set follows.

The first line of a data set has integers nn and WW, then floating-point coordinates xx and yy of the stables. 1≤n≤1001 \leq n \leq 100, 0≤W≤1000 \leq W \leq 100, and (x,y)(x, y) is the stable location.

Each of the next nn lines describes one river. It starts with integer kik_i (2≤ki≤202 \leq k_i \leq 20), the number of points, then integer wiw_i (1≤wi≤1001 \leq w_i \leq 100), the water supplied. The remaining 2ki2k_i numbers are the coordinates (xj,yj)(x_j, y_j) of the river points in order.

Output

For data set xx, print Data Set x: on its own line, then on the next line print the minimum total digging distance to obtain at least WW water, rounded to two decimals. If the rivers cannot supply enough water together, print Impossible. Leave a blank line after each data set.

Examples4

  1. Example 1

    Input
    2
    4 11 0.0 0.0
    2 15 -6.0 0.0 0.0 6.0
    4 5 -4.0 -4.0 -3.0 -3.0 -3.0 3.0 -4.0 4.0
    4 5 -1.5 -4.0 -0.5 -3.0 -0.5 3.0 -1.5 4.0
    4 3 -3.0 0.0 -1.0 0.0 0.0 0.5 5.1 2.1
    1 10 1.5 -0.2
    2 9 -10.0 0 10.0 0
    
    Expected output
    Data Set 1:
    3.95
    
    Data Set 2:
    Impossible
    
  2. Example 2

    Input
    1
    1 0 0.0 0.0
    2 5 0.0 0.0 1.0 0.0
    
    Expected output
    Data Set 1:
    0.00
    
  3. Example 3

    Input
    1
    1 5 0.0 0.0
    2 10 3.0 4.0 0.0 0.0
    
    Expected output
    Data Set 1:
    0.00
    
  4. Example 4

    Input
    1
    1 100 0.0 0.0
    2 50 5.0 0.0 6.0 0.0
    
    Expected output
    Data Set 1:
    Impossible