#P7595. Interactive Tree Discovery

    ID: 20789 Type: Default 1000ms 256MiB

Interactive Tree Discovery

Interactive Tree Discovery

You are given a rooted tree with nn nodes, with node 11 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 uu and vv.
2. Query Type 2: ? 2 u
    This query returns two pieces of information about the subtree rooted at node uu: 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:

! fa[2] fa[3]  fa[n]\displaystyle !\ fa[2]\ fa[3]\ \ldots\ fa[n]

You must ensure that the interactive protocol does not produce more than 10510^5 numbers in total.

inputFormat

The first line contains a single integer nn, which is the number of nodes in the tree.

For the purposes of offline simulation (and testing), the second line contains n1n-1 integers: fa[2],fa[3],,fa[n]fa[2], fa[3], \ldots, fa[n], indicating the parent of each node from 22 to nn.

outputFormat

Output a single line in the following format:

! fa[2] fa[3]  fa[n]\displaystyle !\ fa[2]\ fa[3]\ \ldots\ fa[n]

Here, fa[i]fa[i] is the parent of node ii in the tree.

sample

3
1 1
! 1 1