#P13782. [eJOI 2022] Where Is the Root?
[eJOI 2022] Where Is the Root?
题目背景
This is an interactive problem
题目描述
You are given a tree of vertices. The tree is a graph such that there is exactly one simple path between every pair of vertices. It's also guaranteed that at least one vertex is directly connected by an edge to at least 3 vertices. One of the vertices is the root, and your task is to find it. In order to do this, you are allowed to ask queries of the following form:
- For a given set of vertices, check if their lowest common ancestor is in this set.
A vertex is a common ancestor of a set of vertices if the paths from all vertices in to the root pass through . The lowest common ancestor (LCA) of a set of vertices is the common ancestor of which is farthest from the root.
Interaction
Start the interaction by reading a single integer () - the number of vertices.
Then read next lines. The -th line will contain two integers (), indicating that there is an edge between vertices in the tree.
It's guaranteed that these edges form a tree and at least one vertex is directly connected by an edge to at least 3 vertices.
To ask a query, firstly output "?", then the integer , and then distinct integers (, all are distinct) - vertices, for which you want to check if their LCA is among them.
As a response, the interactor will output "YES" if their LCA is one of , and "NO" otherwise.
You can ask at most 1000 queries, but you'll get a different number of points depending on how many queries you ask. Outputting the answer does not count as a query. Please, look at the scoring section for the details.
When you have identified the root, output the symbol "!" and then one integer () - the root. Then terminate your program.
After printing a query do not forget to output end of line and flush the output. To do this, use:
fflush(stdout)
orcout.flush()
in C++;stdout.flush()
in Python;
It is guaranteed that for each test case, the tree and its root are fixed before the start of the interaction. In other words, the interactor is not adaptive.
7
4 1
1 2
4 3
3 5
3 6
4 7
NO
YES
NO
YES
? 2 5 6
? 3 6 3 5
? 2 1 7
? 2 4 6
! 4
提示
Note
In the first query, the LCA of vertices 5 and 6 is vertex 3 which is not among vertices 5 and 6 so the answer is "NO".
In the second query, the LCA of vertices 3, 5, and 6 is vertex 3 so the answer is "YES".
In the third query, the LCA of vertices 1 and 7 is vertex 4 so the answer is "NO".
In the fourth query, the LCA of vertices 4 and 6 is vertex 4 so the answer is "YES".
After that, we can guess that root is vertex 4 which is the correct answer.
Scoring
- (7 points):
- (10 points):
- (up to 83 points):
In the first and second subtasks you can ask at most 1000 queries.
In the third subtask, let be the maximum number of queries you asked in any test. If , you will get 83 points. Otherwise, you will get $\left\lfloor \max \left(10, 83 \cdot \left(1 - \frac{\ln(k-6)}{7}\right)\right) \right\rfloor$ points.
C++ code that computes the number of points for the third subtask:
((k <= 9) ? 83 : max(10, int(83 * (1 - log(k - 6.0) / 7))))