eolymp
bolt
Try our new interface for solving problems
Problems

The Cyber Traveling Salesman

The Cyber Traveling Salesman

In light of the exploding population on earth, a number of cities are being constructed on the moon. We would like you to assist in determining the best road system for these cities. Considering the high cost associated with building roads on the moon, all what is required is for the roads to form a cycle starting from the city that appears first in the input, passing through all other cities exactly once (but in any arbitrary order,) and then ending back to the first. (Yes, this problem is a variation of the traveling-salesman problem.) You are given the cost of building a road between each pair of cities. Roads are one-way, but the cost for building a road from city \textbf{i} to \textbf{j} is the same as the cost of building from city \textbf{j} to \textbf{i}. When roads intersect at a location that is not a city, you must account for the cost of constructing bypassing bridges. Constructing a bypass system costs \textbf{k·(k-1)·C/2} where \textbf{k} is the number of roads intersecting at that location, and \textbf{C} is a given constant. Note that the cities are laid out so that no three cities fall on the same straight line. \InputFile Your program will be tested on one or more test cases. Each test case is specified using \textbf{2·N+1} lines. The first line specifies two integers: (\textbf{2} < \textbf{N} < \textbf{9}) is the number of cities and (\textbf{0} < \textbf{C} ≤ \textbf{1000000}) is the coefficient used in determining the cost of building bridges. Following the first line, the Cartesian coordinates of the cities are specified in order. Each city is specified on a separate line made of two integers: \textbf{x_i} and \textbf{y_i} where (\textbf{-1000} ≤ \textbf{x_i}, \textbf{y_i} ≤ \textbf{1000}). No two cities are located at the same (\textbf{x}, \textbf{y}) location. The last \textbf{N} lines of a test case specify an \textbf{N}×\textbf{N} matrix representing the cost of building a road between any two cities. The matrix is specified using \textbf{N} lines, each with \textbf{N} integers in a row-major format. The \textbf{j}^th value on the \textbf{i}^th row, denoted as \textbf{c_ij} is the cost of building a road from city-\textbf{i} to city-\textbf{j} where (\textbf{0} < \textbf{c_ij} ≤ \textbf{10^6}) and (\textbf{c_ij} = \textbf{c_ji}) and (\textbf{c_ii} = \textbf{0}). The last case is followed by a line having two zeros. \OutputFile For each test case, print the following line: \textbf{k. M} Where \textbf{k} is the test case number (starting at one,) and \textbf{M} is minimum cost needed to build the road system. \includegraphics{https://static.e-olymp.com/content/19/1931f7ec74076cbd80441c6958d0d8b08bd90a59.jpg}
Time limit 1 second
Memory limit 64 MiB
Input example #1
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
Output example #1
1. 10
2. 20