| Codeforces Round 1076 (Div. 3) |
|---|
| Finished |
This is an interactive problem.
In this interactive problem, you are given an acyclic, connected, undirected graph consisting of $$$n$$$ vertices. We define a path between two vertices $$$v$$$ and $$$u$$$ as a sequence of distinct vertices $$$p_1, p_2,\dots p_k$$$ such that $$$p_1 = v$$$, $$$p_k = u$$$, and for all $$$i$$$ ($$$1 \le i \lt k$$$), there exists an edge between vertices $$$p_i$$$ and $$$p_{i+1}$$$.
There are hidden vertices $$$x$$$ and $$$y$$$ (they may coincide). You can make the following queries:
Note that the interactor is adaptive, which means that the hidden vertices may change depending on your queries, but will not contradict previous queries.
Each test consists of several test cases. The first line contains one integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The following lines describe the test cases.
The first line of each test case contains one integer $$$n$$$ ($$$2\le n\le 2\cdot 10^5$$$) — the number of vertices in the graph.
Next, there are $$$n - 1$$$ lines, each containing two integers $$$v$$$, $$$u$$$ ($$$1\le v, u\le n$$$), indicating that vertices $$$v$$$ and $$$u$$$ are connected by an edge in the graph.
It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.
To find any vertex on the path, you can use no more than $$$\lfloor\frac{n}{2}\rfloor + 1$$$ queries. For this, use queries of the form "? $$$a$$$ $$$b$$$".
After each query, read one number, either $$$0$$$ or $$$1$$$ — the response to the query.
When you find one of the required vertices, output one line in the following format: "! $$$v$$$" ($$$1\le v\le n$$$), where $$$v$$$ is the vertex you found.
If your program makes more than $$$\lfloor\frac{n}{2}\rfloor + 1$$$ queries for one test case, the response to the query will be $$$-1$$$, and after receiving such a response, your program should terminate immediately to receive a verdict of Incorrect answer. Otherwise, it may receive any other verdict.
After outputting a query, do not forget to output a newline and flush the output buffer. Otherwise, you will receive a verdict of Solution "timed out". To flush the buffer, use:
3 2 1 2 1 3 1 2 1 3 0 0 4 1 2 2 3 2 4 0 1
? 1 1 ! 1 ? 1 1 ? 2 2 ! 3 ? 1 3 ? 4 4 ! 4
| Name |
|---|


