luogu#P8303. [CoE R4 C] 网格
[CoE R4 C] 网格
Problem Description
This is an interactive problem.
There is an undirected unweighted graph with vertices.
This graph has a special property: there exists a one-to-one correspondence between a vertex and a pair of positive integers , such that , and there is an edge between vertices if and only if the corresponding pairs satisfy . In other words, this graph is isomorphic to an -row -column grid graph.
Now, you need to recover the structure of this graph using some queries. In each query, you need to provide a vertex . The return value of the query is an array of length , where is the number of edges on the shortest path between vertices and .
You need to recover the structure of the graph using no more than queries.
Interaction Protocol
This problem contains multiple test cases.
First, an integer is given, denoting the number of test cases.
For each test case:
- First, an integer is given, denoting the number of vertices in the graph.
- Then, you may perform some queries. For each query, output an integer , the vertex you query. Then, input integers , the returned values of the query.
- When you are ready to give the answer, output an integer , and then output your answer.
When outputting the answer:
- Output two integers on the first line.
- Next, output lines each containing integers, describing the correspondence you recovered. The number in row , column is the index corresponding to .
If there are multiple answers, you may output any one of them. An answer is considered correct if and only if it cannot be distinguished from the standard answer by any query. That is, in the grid graphs corresponding to these two answers, the number of edges on the shortest path between any pair of vertices is the same.
Please note: after each query or after outputting the answer, you should flush the buffer:
- In C++, use
fflush(stdout)orcout.flush(). - In Java, use
System.out.flush(). - In Python, use
stdout.flush(). - In Pascal, use
flush(output). - For other languages, please refer to the corresponding documentation.
Input Format
See “Interaction Protocol”.
Output Format
See “Interaction Protocol”.
1
6
0 2 2 3 1 1
2 0 2 1 1 3
2 2 0 1 1 1
3 1 1 0 2 2
1 1 1 2 0 2
1 3 1 2 2 0
1
2
3
4
5
6
0
2 3
2 5 1
4 3 6
2
1
2
1 0
0
1 1
1
2
0
2 1
1
2
Hint
Explanation of Sample
For the sample, the following -row -column grid graph is also a correct output.
3 2
4 2
3 5
6 1
The left side is the grid graph corresponding to the sample, and the right side is the grid graph corresponding to the output above.

Scoring Rules
For a subtask, let be the maximum number of queries you used among all testdata in this subtask.
If the interaction protocol is invalid, your program exceeds the time limit, or your answer is incorrect, or , then your score is .
Otherwise, for subtasks , you get full score. For subtask , your score is given by the table below:
| Condition | Score |
|---|---|
Constraints
This problem uses bundled testdata.
| Subtask | Points | Special Property | ||
|---|---|---|---|---|
| None | ||||
| There exists a solution with | ||||
| There exists a solution with | ||||
| None | ||||
For all testdata, it is guaranteed that , , and .
In some testdata, the interactor is adaptive. That is, the structure of the graph may change according to your queries. However, it is guaranteed that after each query, there exists at least one answer consistent with all returned values so far.
Translated by ChatGPT 5