#arc142c. [arc142_c]Tree Queries
[arc142_c]Tree Queries
Problem Statement
There is a tree with vertices, numbered .
For each pair of integers , the distance between Vertices is defined as the following.
- The number of edges contained in the shortest path connecting Vertices and .
You are allowed to ask between and questions (inclusive) in the following form.
- Ask the distance between Vertices for integers of your choice such that and .
Find the distance between Vertices .
Constraints
- is an integer.
- The tree is determined before the start of the interaction between your program and the judge.
Input and Output
This is an interactive task, in which your program and the judge interact via input and output.
First, your program is given a positive integer from Standard Input:
Then, you get to ask questions.
A question should be printed in the following format (with a newline at the end):
?
If the question is valid, the response is given from Standard Input:
If the question is judged invalid because, for example, it is malformed or you have asked too many questions, you get -1
instead of the response:
-1
At this point, your submission is already judged incorrect. The judge's program then terminates; yours should too, desirably.
When you find the answer , print it to Standard Output in the following format (with a newline at the end):
!
Notices
- Flush Standard Output after each output. Otherwise, you might get the TLE