Problem hidden
|This problem was hidden by Editorial Board member probably because it has incorrect language|version or invalid test data, or description of the problem is not clear.|
Problem hidden on 2015-03-19 16:51:43 by Thích code nhưng dốt

PTIT134F - Mê cung Domino

 

Mister No (real name Jerry Drake) is a comic book character who frequently gets himself into a lot of trouble, which he is usually able to get out of. However, this time it's not so easy. He was searching for ancient Mayan treasures and, in the process, stumbled upon a lost temple. Inside the temple there is a large hall, and inside the hall stands a stone Totem with inscriptions that are the key to understanding the purpose of life (42). However, getting to the Totem is a great challenge.
The Totem is situated on the opposite side of the hall form the entrance. The floor of the hall is covered with stone tiles that bear a striking resemblance to domino tiles. Each tile is divided into two halves (squares), and each half has a number from one to six, inclusive, chiseled into it. Tiles are arranged in N rows, with N tiles in each odd-numbered row and N - 1 tiles in each even-numbered row. The image below corresponds to the first test example (N = 5):

Mister No (real name Jerry Drake) is a comic book character who frequently gets himself into a lot of trouble, which he is usually able to get out of. However, this time it's not so easy. He was searching for ancient Mayan treasures and, in the process, stumbled upon a lost temple. Inside the temple there is a large hall, and inside the hall stands a stone Totem with inscriptions that are the key to understanding the purpose of life (42). However, getting to the Totem is a great challenge.

The Totem is situated on the opposite side of the hall form the entrance. The floor of the hall is covered with stone tiles that bear a striking resemblance to domino tiles. Each tile is divided into two halves (squares), and each half has a number from one to six, inclusive, chiseled into it. Tiles are arranged in N rows, with N tiles in each odd-numbered row and N - 1 tiles in each even-numbered row. The image below corresponds to the first test example (N = 5):

It is only possible to step from one tile to an adjacent one if the two tiles have matching numbers on halves that share an edge. Help Mister No find the shortest path to the Totem by determining the sequence of tiles (outputting the sequence of tiles' labels, described below) that need to be stepped on, in order, from the first to the last tile on the path. If there is no possible path to the Totem, find the shortest path to the tile with the largest label (so that Mister No can make a heroic jump). The stone tiles are labelled in row-major order: in the first row, the first tile has the label 1, and the last one N; in the second row, the first tile is N + 1, and the last one 2*N - 1, and so on. The entrance leads to the tile with label 1, and the totem is on the last tile in the last row. Mister No always starts from the entrance.

Input

The first line of input contains the positive integer N (1 ≤ N ≤ 500), the number of stone tile rows.

Each of the following N * N - N / 2 lines (where “/” stands for integer division) contains two positive integers Ai and Bi (1 ≤ Ai, Bi ≤ 6, 1 ≤ i ≤ N * N - N / 2), the values chiseled into the left and right halves, respectively, of tile i.

Output

The first line of output must contain the length (in tiles) of the required shortest path.

The second line of output must contain a sequence of space-separated positive integers, the labels of tiles on the shortest path. As there can exist more than one shortest path, output any one of them.

Example

input
1 4 
4 5 
3 4 
5 4 
5 2 
4 2 
5 6 
4 4 
6 5 
2 4 
5 1 
6 1 
1 6 
2 3 
4 2 
5 3 
1 2 
5 5 
4 1 
2 2 
4 3 
2 3
3 4
output
1 2 7 12 17 22 23

input
1 2 
2 3 
6 6 
2 4 
3 5 
6 6 
4 5 
5 6
output
1 2 5 8

input
1 5 
5 3 
5 5 
5 6 
5 3 
6 4 
4 5 
2 5 
2 4 
4 3 
2 4 
5 2 
1 4 
1 6
output
1 5 8 12 9 10 13

Được gửi lên bởi:adm
Ngày:2013-02-28
Thời gian chạy:1s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:ASM32-GCC ASM32 MAWK BC C CSHARP C++ 4.3.2 CPP CPP14 COFFEE LISP sbcl DART FORTH GO JAVA JS-RHINO JS-MONKEY KTLN OCT PAS-GPC PAS-FPC PERL PERL6 PROLOG PYTHON PYTHON3 PY_NBC R RACKET SQLITE SWIFT UNLAMBDA
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.