#P7597. 「EZEC-8」猜树 加强版
「EZEC-8」猜树 加强版
Description
There is a rooted tree with nodes, rooted at . You need to determine the structure of this tree through several queries.
You can use two types of queries:
? 1 u vWith this query, you can get the distance between and .? 2 uWith this query, you can get the size of the subtree of and all nodes in the subtree of .
Please determine the structure of the tree while making the interactive library output no more than numbers.
Interaction
Input the size of the tree to start the interaction.
During the interaction, you may make the two types of queries described above.
For the first type of query, the interactive library will return a non-negative integer, which is the distance between node and node .
For the second type of query, the interactive library will first return a positive integer , which is the size of the subtree of . Then, on the same line, it will return positive integers, which are all nodes in the subtree of (the order of the nodes will be shuffled).
After you have determined the answer, output one line in the form ! fa[2] fa[3] ... fa[n] to stop the interaction, where denotes the parent of node in this tree.
After you output a line, please flush the buffer:
- In C++, use
fflush(stdout)orcout.flush(). - In Pascal, use
flush(output). - In Python, use
stdout.flush(). - For other languages, please check the documentation by yourself.
Input Format
See "Interaction".
Output Format
See "Interaction".
5
1
5 1 5 2 4 3
3 4 2 5
1 3
? 1 1 2
? 2 1
? 2 2
? 2 3
! 1 1 2 2
Hint
For of the testdata: , .
Translated by ChatGPT 5
京公网安备 11011102002149号