﻿ URI 1076 - Design Labirints
URI Online Judge | 1076

# Design Labirints

By Neilor Tonin, URI Brazil

Timelimit: 1

Peter loves to draw mazes, and recently he had an idea: which would be the minimum of pen movements needed to draw a maze, always beginning and finishing at the same position? To make the game more interesting, Peter decided that it is not allowed to lift the pen from the paper. The templates for construction of the maze are always square, 3 x 3, 4 x 4, 5 x 5 up to a maximum of 7 x 7.

For each example, Peter will specify where the drawing must start and your task is to determine the amount of movements required to draw the Peter's maze. Peter remembers that you do not have to worry about cycles, because there will be no cycles in any of the test cases. However, a test case can have an input 4 1 and another input 1 4. This means two lines connecting these same two nodes. Anyway it will make no difference in the drawing of the labyrinth because the amount of movement should be the same.

See the examples below, In the maze(4 x 4), Peter wants to begin in the node 0, draw all lines and return to node 0. For this, the minimum of possible moves is 30. In the maze B (3 x 3), Pedro begins in the node 1, draws all lines and returns to node 1. In this case, he needs 10 movements to make this drawing.