#P7595. 「EZEC-8」猜树
「EZEC-8」猜树
Description
There is a rooted tree with nodes, rooted at . You need to determine the structure of this tree by making several queries.
You may use two types of queries:
? 1 u vUsing this query, you can obtain the distance between and .? 2 uUsing this query, you can obtain 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
The interaction starts by reading the tree size .
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, representing the distance between node and node .
For the second type of query, the interactive library will first return a positive integer , representing the size of the subtree of . Then, on the same line, it will return positive integers, representing all nodes in the subtree of (the order of nodes will be shuffled).
After you have determined the answer, output one line in the form ! fa[2] fa[3] ... fa[n] and stop the interaction. Here, denotes the parent of node in this tree.
After outputting a line, 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 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
This problem uses bundled testdata.
- Subtask 1 (5 points): .
- Subtask 2 (15 points): .
- Subtask 3 (20 points): .
- Subtask 4 (15 points): the tree is a chain.
- Subtask 5 (15 points): the tree is a complete binary tree.
- Subtask 6 (30 points): no special constraints.
For of the data: , .
Note: continuing to query after making an invalid query or after the interactive library has output more than numbers may cause TLE.
Translated by ChatGPT 5
京公网安备 11011102002149号