#P10553. [ICPC2024 Xi'an I] Guess The Tree

    ID: 10005 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>2024交互题Special JudgeO2优化ICPC

[ICPC2024 Xi'an I] Guess The Tree

题目描述

There is a full binary tree with nn levels(so it has exactly 2n12^n-1 nodes). Each node has an integer ID from 11 to 2n12^n-1, and the 2n12^n-1 IDs form an arrangement from 11 to 2n12^n-1, but you don't know.

You need to find the IDs of the 2n12^n-1 nodes using at most 48004800 queries.

输入格式

The first line contains one integer n(1n10)n(1\leq n\leq 10), the levels of the full binary tree.

To ask a query, you need to pick two nodes with IDs u,v(1u,v2n1)u,v(1\leq u,v\leq 2^n-1), and print the line of the following form:

"? u v"

After that, you will receive:

"t"

The lowest common ancestor's ID of uu and vv.

You can ask at most 48004800 queries.

If you have found the structure of the tree, print a line of the following form:

"! f1 f2 f3 f4f_1\ f_2\ f_3\ f_4 ... f2n1f_{2^n-1}"

fif_i means the i-th node's father's ID. If it has no father, then fi=1f_i=-1.

After printing a query or the answer for a test case, do not forget to output the end of line and flush the output. Otherwise, you will get the verdict 'Idleness Limit Exceeded'. To do this, use:

fflush(stdout) or cout.flush() in C++;

System.out.flush() in Java;

stdout.flush() in Python.

The interactor in this task is not adaptive.

2

3

3

3

? 1 2

? 2 3

? 1 3

! 3 3 -1

提示

In this case, the tree's root is 33, it's two sons are 11 and 22.

For any query "? a b",if aba\neq b, the jury will return answer 33.

So we found the tree's root is 33 .