This page is still under construction.

Parts of this page are still being built. What you see may change.

Connecting Islands

Time limit1sMemory limit128 MB

Summary
Connect all island polygons with bridges between vertices, each bridge crossing only water, minimizing the total length of the bridges.
Level

Medium7 of 10

Topics
Geometry, Minimum spanning tree, Union-find, Sorting
Solved
No attempts yet

Problem

We want to connect a group of islands with bridges so that any island can be reached from any other island. Because the cost of a bridge is proportional to its length, we want to keep the total cost down by minimizing the total length of the bridges needed to connect all the islands. Write a program that determines this minimum total bridge length.

Each island is represented by a polygon, and to keep things simple a bridge may only run between corners (vertices) of two different polygons. A bridge may only run over water; it may not pass over any island's land. Two bridges are, however, allowed to cross each other. Note that the shape of an island may be non-convex.

Input

The first line contains the number of test cases.

Each test case begins with a line containing the number of islands NN (2≤N≤152 \le N \le 15). The next NN lines each describe one island. An island is a polygon given by an integer PP (1≤P≤251 \le P \le 25), the number of vertices, followed by PP coordinate pairs x yx\ y. Each coordinate is an integer in the range [−1000,1000][-1000, 1000]. The vertices are listed in order, so that connecting consecutive vertices, and the last vertex back to the first, traces the island's shore.

It is guaranteed that islands neither touch nor intersect.

Output

For each test case, print two lines in the following format:

The minimal interconnect consists of B bridges
with a total length of L.

Here BB is the number of bridges built and LL is their total length, printed with exactly three digits after the decimal point.

Examples6

  1. Example 1

    Input
    1
    3
    4 0 0 0 1 1 1 1 0
    4 2 0 2 1 3 1 3 0
    3 4 0 5 0 5 1
    
    Expected output
    The minimal interconnect consists of 2 bridges
    with a total length of 2.000.
    
  2. Example 2

    Input
    1
    2
    4 0 0 0 1 1 1 1 0
    4 3 0 3 1 4 1 4 0
    
    Expected output
    The minimal interconnect consists of 1 bridges
    with a total length of 2.000.
    
  3. Example 3

    Input
    1
    4
    4 0 0 0 1 1 1 1 0
    4 2 0 2 1 3 1 3 0
    4 4 0 4 1 5 1 5 0
    4 6 0 6 1 7 1 7 0
    
    Expected output
    The minimal interconnect consists of 3 bridges
    with a total length of 3.000.
    
  4. Example 4

    Input
    1
    2
    4 0 0 0 1 1 1 1 0
    4 2 2 2 3 3 3 3 2
    
    Expected output
    The minimal interconnect consists of 1 bridges
    with a total length of 1.414.
    
  5. Example 5

    Input
    1
    3
    4 0 0 0 2 2 2 2 0
    4 7 0 7 2 9 2 9 0
    4 3 -30 3 30 4 30 4 -30
    
    Expected output
    The minimal interconnect consists of 2 bridges
    with a total length of 56.178.
    
  6. Example 6

    Input
    2
    2
    4 0 0 0 1 1 1 1 0
    4 3 0 3 1 4 1 4 0
    2
    4 0 0 0 1 1 1 1 0
    4 2 2 2 3 3 3 3 2
    
    Expected output
    The minimal interconnect consists of 1 bridges
    with a total length of 2.000.
    The minimal interconnect consists of 1 bridges
    with a total length of 1.414.