Where Is the Root?

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

This is an interactive problem.

You are given a tree of n 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 33 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 a_1,a_2,,a_ma\_1 , a\_2 , \dots , a\_m of vertices, check if their lowest common ancestor is in this set.

A vertex vv is a common ancestor of a set SS of vertices if the paths from all vertices in SS to the root pass through vv. The lowest common ancestor (LCA) of a set SS of vertices is the common ancestor of SS which is farthest from the root.

힌트

The hidden root is vertex 44.

In the first query, the LCA of vertices 55 and 66 is vertex 33 which is not among vertices 55 and 66 so the answer is "NO".

In the second query, the LCA of vertices 33, 55, and 66 is vertex 33 so the answer is "YES".

In the third query, the LCA of vertices 11 and 77 is vertex 44 so the answer is "NO".

In the fourth query, the LCA of vertices 44 and 66 is vertex 44 so the answer is "YES".

After that, we can guess that root is vertex 44 which is the correct answer.