7581: Easy NPC Problem

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

It is preferrable to read the pdf statment.
Cuber QQ fell in love with research of NPC problem. He is very passionate in those cutting-edge thinkings, especially in Hamiltonian path problem, which is a well-known typical NPC problem.
In the mathematical field of graph theory, a Hamiltonian path is a path in an undirected or directed graph that visits each vertex exactly once. Mathematicians have spent hundreds of years, trying to find a general yet elegant solution of this problem, but still, the problem is only solved in a limited scope.
Cuber QQ wants to take one step forward, by solving the Hamiltonian path problem in the grid. A grid has n×m vertices. We use a typical coordinate system in the grid, where each vertex on the grid is labelled by a pair of integers (x,y) (1≤x≤n,1≤y≤m), and it is connected to adjacent vertices (if they are available), i.e., (x−1,y), (x+1,y), (x,y−1), (x,y+1).
The problem seems too trivial to him, Cuber QQ will take another step forward to find a Hamiltonian path in the grid without visiting the vertex (Nx,Ny) (1≤Nx≤n,1≤Ny≤m), and the starting vertex must be located at (Sx,Sy) (1≤Sx≤n,1≤Sy≤m). It is a little too difficult for him now and he asks you for help.

输入格式

The first line contains an integer T (T≤2 500), denoting the number of test cases.
Each test case has six space-separated integers n,m,Nx,Ny,Sx,Sy (1≤Nx,Sx≤n≤200, 1≤Ny,Sy≤m≤200, Nx≠Sx or Ny≠Sy) in one line.
It is guaranteed that ∑n+m≤105.

输出格式

For each test case, if there is no solution, print a single integer −1 in one line, otherwise the first line output an integer nm−1, which is the length of the path. The next nm−1 lines contain the vertices in the visiting order. and each of the n lines contains two space-separated integers x,y (1≤x≤n,1≤y≤m).
If there are multiple solutions, print any.

输入样例 复制

2
2 4 1 2 1 1
2 4 2 2 1 1

输出样例 复制

7
1 1
2 1
2 2
2 3
2 4
1 4
1 3
-1

分类标签