Building Moon City

Time limit1sMemory limit128 MB

Summary
Find a Hamiltonian cycle over fewer than 9 planets minimizing road costs plus a penalty for each pair of edges that cross.
Level

Medium7 of 10

Topics
Brute force, Geometry, Greedy, Implementation
Solved
No attempts yet

Problem

Science and technology have advanced enough that cities can now be built on the Moon. Because construction on the Moon is extremely expensive, when there are NN cities we want to build as few connecting roads as possible. Specifically, we want the roads to form a single cycle of size NN that visits every city exactly once.

For each pair of cities, the cost of building a (two-way) road between them is fixed. Building a road between city ii and city jj lets you travel in both directions with no extra construction. So far this is very similar to the Traveling Salesman Problem, but here there is an additional cost.

Every road must be built as a straight line segment whose endpoints are the two cities. If two different roads cross at a point that is not a city, one of them must detour around the other, which incurs an extra cost. If kk roads all cross at a single non-city point, the extra cost incurred at that point is k(k−1)C2\dfrac{k(k-1)C}{2}, where CC is a constant given in the input. No three cities are collinear.

Find the minimum total cost of building the roads so that the conditions are satisfied.

Input

The input consists of several test cases. Each test case has the format below, and the end of the input is marked by 0 0 in place of a test case.

The first line of each test case contains two integers NN and CC (2<N<92 < N < 9, 0<C≤1,000,0000 < C \le 1{,}000{,}000). NN is the number of cities and CC is the constant used for the crossing penalty.

The next NN lines give the coordinates of the cities. The ii-th of these lines contains two integers xix_i and yiy_i, the coordinates of city ii (−1,000≤xi,yi≤1,000-1{,}000 \le x_i, y_i \le 1{,}000). No two cities share the same location.

The following NN lines give an N×NN \times N cost matrix. The jj-th value on the ii-th line, cijc_{ij}, is the cost of building a road from city ii to city jj (0<cij≤1060 < c_{ij} \le 10^6, cij=cjic_{ij} = c_{ji}, cii=0c_{ii} = 0).

Output

For each test case, print the answer on one line using the following format.

(test case number). (answer)

The test case number starts at 11 and increases by 11.

Examples1

  1. Example 1

    Input
    4 1
    1 2
    0 1
    2 1
    1 0
    0 1 8 3
    1 0 3 9
    8 3 0 2
    3 9 2 0
    4 100
    1 2
    0 1
    2 1
    1 0
    0 1 8 3
    1 0 3 9
    8 3 0 2
    3 9 2 0
    0 0
    
    Expected output
    1. 10
    2. 20