| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 122 | 23 | 17 | 18.681% |
You are given a rooted binary tree consisting of $N$ vertices. The vertices are numbered from $1$ to $N$, the root is the vertex number $1$. Each of the other vertices has a single parent in the tree. The tree is binary, i.e. each vertex can be a parent of at most two other vertices.
One of the vertices is special. You are trying to guess it. You can ask the questions of the following kind: "Is the special vertex in the subtree of vertex $x$"? A node $y$ is in the subtree of vertex $x$ if and only if the shortest path between $y$ and $1$ goes through vertex $x$. Note that vertex $x$ is also in its own subtree.
You are allowed to ask this question at most $35$ times. After that you should report your guess.
You should implement the following procedure:
int solve(int N, std::vector < int > p)
The above procedure can make calls to the following procedure:
int ask(int x)
Consider the following call:
solve(5, [1, 1, 2, 4])
The tree consists of the edges $(1,2)$, $(1,3)$, $(2,4)$ and $(4,5)$.
Your program made a call
ask(4)
which returned $1$. After that your program made a call
ask(5)
which returned $0$.
Your program concluded that vertex $4$ is special and returned $4$.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 20 | $N ≤ 35$ |
| 2 | 30 | $p[i] = i + 1$ for each $0 ≤ i ≤ N - 2$ |
| 3 | 15 | $p[i] = \lfloor i/2 \rfloor + 1$ for each $0 ≤ i ≤ N - 2$ |
| 4 | 35 | No additional constraints. |
The sample grader reads the input in the following format:
The sample grader outputs each question in the following format:
The sample grader reads each answer in the following format:
The sample grader outputs the guess in the following format:
C++17, C++20, C++17 (Clang), C++20 (Clang)