File size: 1,316 Bytes
837b66f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
This is an interactive problem. Misuki has chosen a secret tree with $n$ nodes, indexed from $1$ to $n$, and asked you to guess it by using queries of the following type: * "? a b" — Misuki will tell you which node $x$ minimizes $|d(a,x) - d(b,x)|$, where $d(x,y)$ is the distance between nodes $x$ and $y$. If more than one such node exists, Misuki will tell you the one which minimizes $d(a,x)$. Find out the structure of Misuki's secret tree using at most $15n$ queries! Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 200$) — the number of test cases. Each test case consists of a single line with an integer $n$ ($2 \le n \le 1000$), the number of nodes in the tree. It is guaranteed that the sum of $n$ across all test cases does not exceed $1000$. A tree is an undirected acyclic connected graph. A tree with $n$ nodes will always have $n-1$ edges. In the example case, the answer to "? 1 2" is $1$. This means that there is an edge between nodes $1$ and $2$. The answer to "? 1 3" is $1$. This means that there is an edge between nodes $1$ and $3$. The answer to "? 1 4" is $3$. It can be proven that this can only happen if node $3$ is connected to both node $1$ and $4$. The edges of the tree are hence $(1,2)$, $(1,3)$ and $(3,4)$. |