eolymp
bolt
Try our new interface for solving problems
Problems

Gridland

Gridland

For years, computer scientists have been trying to find efficient solutions to different computing problems. For some of them efficient algorithms are already available, these are the "easy" problems like sorting, evaluating a polynomial or finding the shortest path in a graph. For the "hard" ones only exponential-time algorithms are known. The traveling-salesman problem belongs to this latter group. Given a set of N towns and roads between these towns, the problem is to compute the shortest path allowing a salesman to visit each of the towns once and only once and return to the starting point. The president of Gridland has hired you to design a program that calculates the length of the shortest traveling-salesman tour for the towns in the country. In Gridland, there is one town at each of the points of a rectangular grid. Roads run from every town in the directions North, Northwest, West, Southwest, South, Southeast, East, and Northeast, provided that there is a neighbouring town in that direction. The distance between neighbouring towns in directions NorthSouth or EastWest is \textbf{1} unit. The length of the roads is measured by the Euclidean distance. For example, the figure below shows \textbf{2}×\textbf{3}-Gridland, i.e., a rectangular grid of dimensions \textbf{2} by \textbf{3}. In \textbf{2}×\textbf{3}-Gridland, the shortest tour has length \textbf{6}. \includegraphics{https://static.e-olymp.com/content/31/319d9327e3de12fa8f6cce888c87f7250ee03513.jpg} A traveling-salesman tour in \textbf{2}×\textbf{3}-Grigland \InputFile The first line contains the number of scenarios. For each scenario, the grid dimensions \textbf{m} and \textbf{n} will be given as two integer numbers in a single line, separated by a single blank, satisfying \textbf{1} < \textbf{m} < \textbf{50} and \textbf{1} < \textbf{n} < \textbf{50}. \OutputFile The output for each scenario begins with a line containing "\textbf{Scenario #i:}", where \textbf{i} is the number of the scenario starting at \textbf{1}. In the next line, print the length of the shortest traveling-salesman tour rounded to two decimal digits. Output for the neighboring scenario separated by blank lines.
Time limit 1 second
Memory limit 64 MiB
Input example #1
2
2 2
2 3
Output example #1
Scenario #1:
4.00

Scenario #2:
6.00