Upload code_segments/segment_218.txt with huggingface_hub
Browse files
code_segments/segment_218.txt
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This is an interactive problem.
|
| 2 |
+
|
| 3 |
+
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:
|
| 4 |
+
|
| 5 |
+
* "? 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)$.
|
| 6 |
+
|
| 7 |
+
Find out the structure of Misuki's secret tree using at most $15n$ queries!
|
| 8 |
+
|
| 9 |
+
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.
|
| 10 |
+
|
| 11 |
+
Each test case consists of a single line with an integer $n$ ($2 \le n \le 1000$), the number of nodes in the tree.
|
| 12 |
+
|
| 13 |
+
It is guaranteed that the sum of $n$ across all test cases does not exceed $1000$.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
A tree is an undirected acyclic connected graph. A tree with $n$ nodes will always have $n-1$ edges.
|
| 18 |
+
|
| 19 |
+
In the example case, the answer to "? 1 2" is $1$. This means that there is an edge between nodes $1$ and $2$.
|
| 20 |
+
|
| 21 |
+
The answer to "? 1 3" is $1$. This means that there is an edge between nodes $1$ and $3$.
|
| 22 |
+
|
| 23 |
+
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$.
|
| 24 |
+
|
| 25 |
+
The edges of the tree are hence $(1,2)$, $(1,3)$ and $(3,4)$.
|