#P7595. Interactive Tree Discovery
Interactive Tree Discovery
Interactive Tree Discovery
You are given a rooted tree with nodes, with node as the root. Your task is to determine the structure of the tree by making a series of queries.
There are two types of queries available:
1. Query Type 1: ? 1 u v
This query returns the distance between nodes and .
2. Query Type 2: ? 2 u
This query returns two pieces of information about the subtree rooted at node : first, the size of the subtree, and then a list of all nodes in this subtree (in arbitrary order).
Once you are confident about the tree structure, output the parent of every node (excluding the root) in the format:
You must ensure that the interactive protocol does not produce more than numbers in total.
inputFormat
The first line contains a single integer , which is the number of nodes in the tree.
For the purposes of offline simulation (and testing), the second line contains integers: , indicating the parent of each node from to .
outputFormat
Output a single line in the following format:
Here, is the parent of node in the tree.
sample
3
1 1
! 1 1