Codeforces Global Round 30 (Div. 1 + Div. 2)
G
Pointless Machine
Codeforces
3300
原题
← F2H →
翻译中…

This is an interactive problem.

翻译中…

Madeline is playing with a pointless machine. The pointless machine has a hidden tree of size $n$, and Madeline has to find the edges of the tree by asking the machine.

翻译中…

In a query, Madeline will give the machine a permutation $p$ of $[1,2,\ldots,n]$, and the machine will return a sequence $q_1, q_2, \ldots, q_n$, where $q_i$ is the number of edges of the induced subgraph formed by the vertices $\{p_1,p_2,\ldots,p_i\}$.

翻译中…

Here, an induced subgraph of a graph $G(V,E)$ formed by a subset of vertices $V' \subseteq V$, is a graph consisting of vertices from this subset and all edges between vertices from subset that are present in original graph $G$.

翻译中…

However, the machine works slowly, so Madeline can only get the results at once after all queries are completed. The memory of this machine is not very large either, so Madeline can only ask $31$ times. She doesn't know how to solve it, so she invited you to help her.

翻译中…

Note that the interactor is non-adaptive. That is, tree is fixed in advance and doesn't change with your queries.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The only line of each test case contains a single integer $n$ ($3\le n\le 5\cdot 10^4$) — the size of the tree.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $5\cdot 10^4$.

翻译中…

Interaction

翻译中…

The interaction begins by reading the integer $n$.

翻译中…

Then, output a single integer $k$ ($1 \leq k \leq 31$) — the number of queries.

翻译中…

To ask a query, output a line in the following format:

翻译中…
  • $p_{i,1}\,p_{i,2}\,\ldots\,p_{i,n}$ ($1 \leq p_{i,j} \leq n$, the $p_{i,j}$ are distinct for each $i$) — a query described above.
翻译中…

Once you've asked all $k$ queries, read $k$ lines of $n$ integers $q_{i,j}$ — the responses to the queries as described above.

翻译中…

When you know the hidden tree, output $n-1$ lines in the following format:

翻译中…
  • $u,v$ ($1\leq u,v\leq n$) — an edge $(u,v)$ in the hidden tree.
翻译中…

Then, move on to the next test case, or terminate the program if there are no more test cases.

翻译中…

After printing all $k$ queries do not forget to output the end of line and flush$^{\text{∗}}$ the output. Otherwise, you will get Idleness limit exceeded verdict.

翻译中…

If, at any interaction step, you read $-1$ instead of valid data, your solution must exit immediately. This means that your solution will receive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.

翻译中…

Hacks

翻译中…

To hack, use the following format.

翻译中…

The first line should contain a single integer $t$ ($1 \le t \le 10^4$).

翻译中…

The second line of each test case should contain a single integer $n$ ($3 \le n \le 5\cdot 10^4$).

翻译中…

$i$-th out of next $n - 1$ lines should contain two integers $u_i, v_i$ ($1 \le u_i, v_i \le n$).

翻译中…

Given edges should form a tree, and the sum of $n$ over all test cases shouldn't exceed $5 \cdot 10^4$.

翻译中…

$^{\text{∗}}$To flush, use: fflush(stdout) or cout.flush() in C++; sys.stdout.flush() in Python; see the documentation for other languages.

翻译中…

Note

翻译中…
翻译中…

For the first test case:

翻译中…
  • The first query has answer 0 1 2, since only edge $(1, 2)$ is in the induced subgraph formed by $\{1,2\}$.
  • The second query has answer 0 0 2, since no edges are in the induced subgraph formed by $\{1,3\}$.
翻译中…

For the third test case:

翻译中…
  • Edges $(2,3)$, $(3,4)$, and $(4,1)$ are in the induced subgraph formed by $\{1,2,3,4\}$, so $q_{1,4}=3$.
翻译中…

样例

Input #1
3
3

0 1 2
0 0 2

4

0 1 1 3
0 1 1 3
0 1 2 3

5

0 0 1 3 4
Output #1
2
1 2 3
1 3 2

1 2
2 3

3
3 2 4 1
1 4 3 2
1 2 3 4

2 3
1 2
4 1

1
1 2 3 4 5

1 4
4 3
3 2
5 3
InputCopy OutputCopy
题目信息
题号
2164G
时间限制
4 s
内存限制
256 MB
标签
构造
图论
交互题
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。