| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 2048 MB | 36 | 3 | 3 | 10.000% |
You are active as a thief in JOI galaxy.
There are $N$ stars numbered from $0$ to $N - 1$ in JOI galaxy. There are $M$ warp devices numbered from $0$ to $M -1$ in JOI galaxy. The warp device $i$ ($0 ≤ i ≤ M -1$) connects star $U_i$ and star $V_i$ bidirectionally. It is possible to travel from any star to any star by using warp devices.
A key is hidden in a certain star, and a treasure box is hidden in another certain star. Your mission is to specify numbers, the number of the star in which the key is hidden and in which the treasure box is hidden. To achieve your mission, you can ask questions up to $300$ times as below.
You want to specify numbers, the number of the star $A$ in which the key is hidden and the star $B$ in which the treasure box is hidden. To achieve a higher evaluation, you want to reduce the number of questions asked.
Given information about the galaxy, write a program that determines the star $A$ in which the key is hidden and the star $B$ in which the treasure box is hidden, by asking questions.
The file is thief.cpp. It should implement the following function. The program should include thief.h using the preprocessing directive #include.
void solve(int N, int M, std::vector<int> U, std::vector<int> V)
This function is called only once for each test case.
N is the number of stars $N$.M is the number of warp devices $M$.U, V are arrays of length $M$. For each $i$ ($0 ≤ i ≤ M - 1$), U[i] and V[i] represent the stars $U_i$ and $V_i$ connected bi-directionally by the warp device $i$.Within thief.cpp, your program can call the following function:
int query(std::vector<int> x)
Using this function, you can ask a question.
x is an array of length $M$. For $0 ≤ i ≤ M - 1$:
x[i]$= 0$, it means to allow travel only from star $U_i$ to star $V_i$.x[i]$= 1$, it means to allow travel only from star $V_i$ to star $U_i$.x should be $M$. If not, your program is judged as Wrong Answer [1].x should be $0$ or $1$. If not, your program is judged as Wrong Answer [2].void answer(int A, int B)
You call this function to answer the number of the star $A$ in which the key is hidden and the star $B$ in which the treasure box is hidden.
A represents that the key is hidden in the star $A$.A must be between $0$ and $N - 1$, inclusive. If not, your program is judged as Wrong Answer [4].B represents that the treasure box is hidden in the star $A$.B must be between $0$ and $N - 1$, inclusive. If not, your program is judged as Wrong Answer [5].answer should be called exactly once. If the function answer is called more than once, your program is judged as Wrong Answer [7]. When the function solve terminates, if the function answer is not called, your program is judged as Wrong Answer [8].Important Notices
You can download an archive file from the contest webpage which contains the sample grader to test your program. The archive file also contains a sample source file of your program.
The sample grader is the file grader.cpp. In order to test your program, put grader.cpp, thief.cpp, thief.h in the same directory, and run the following command to compile your programs.
g++ -std=gnu++20 -O2 -o grader grader.cpp thief.cpp
Instead, you may run compile.sh contained in the archive file. In this case, run the following command to compile your programs.
./compile.sh
When the compilation succeeds, the executable file grader is generated. Note that the actual grader is different from the sample grader. The sample grader will be executed as a single process, which will read input data from the standard input and write the results to the standard output.
Input for the Sample Grader
The sample grader reads the following data from the standard input.
$N$ $M$ $A$ $B$
$U_0$ $V_0$
$U_1$ $V_1$
$\vdots$
$U_{M-1}$ $V_{M-1}$
Output of the Sample Grader
The sample grader outputs the following information to the standard output (quotes for clarity).
Accepted: 25”.Wrong Answer [4]”.If your program satisfies the conditions of several types of Wrong Answer, the sample grader reports only one of them. The sample grader may terminate the execution when one of the conditions for wrong answer is met.
For some of the test cases, the actual grader is adaptive. This means the grader does not have a fixed answer in the beginning, and responds according to previous function calls to query. It is guaranteed that there is at least one answer which does not contradict all the responses of the the grader.
All the input data satisfy the following conditions.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 7 | $M = N - 1$, $U_i = i$, $V_i = i + 1$ ($0 ≤ i ≤ M - 1$). |
| 2 | 13 | $M = N - 1$, $U_i = 0$, $V_i = i + 1$ ($0 ≤ i ≤ M - 1$). |
| 3 | 2 | $M = N - 1$, $N ≤ 8$. |
| 4 | 8 | $M = N - 1$, $N ≤ 50$. |
| 5 | 5 | $M = N - 1$, $N ≤ 150$. |
| 6 | 5 | $M = N - 1$, $N ≤ 250$. |
| 7 | 40 | $M = N - 1$. In this subtask, points are awarded as follows:
|
| 8 | 20 | No additional constraints. In this subtask, points are awarded as follows:
|
The scores for Subtasks 1, 2, 3, 4, 5, 6 do not depend on the number of function calls to query, as long as it does not exceed $300$. However, when it is more than $70$, the contest system might display “Output is partially correct”.
Here is a sample input for the sample grader and corresponding function calls.
| Sample Input 1 | Sample Function Calls | ||
|---|---|---|---|
| Function Calls | Function Calls | Return Values | |
5 4 0 4 0 1 0 3 1 2 1 4 |
solve(5, 4, [0, 0, 1, 1], [1, 3, 2, 4]) |
||
query([0, 1, 0, 0]) |
1 |
||
query([1, 1, 1, 0]) |
0 |
||
query([0, 0, 1, 0]) |
1 |
||
query([0, 0, 1, 1]) |
0 |
||
answer(0, 4) |
|||
Choices corresponding to the $1$-st function call to query are as below:
Under these conditions, it is possible to travel from star $0$ to star $4$ by using warp devices $0$ and $3$ in this order, so the return value is $1$.
Choices corresponding to the $2$-nd function call to query are as below:
Under these conditions, it is not possible to travel from star $0$ to star $4$ by using warp devices, so the return value is $0$.
Choices corresponding to the $3$-rd function call to query are as below:
Under these conditions, it is possible to travel from star $0$ to star $4$ by using warp devices, so the return value is $1$.
Under the conditions of the choices corresponding to the $4$-th function call to query, it is not possible to travel from $0$ to star $4$ by using warp devices, so the return value is $0$.
The function call to answer represents that you answer that star $A$ is star $0$, and star $B$ is star $4$.
This Sample Input satisfies the constraints of Subtasks 3, 4, 5, 6, 7, 8. Among the files which can be obtained from the contest webpage, sample-01-in.txt corresponds to Sample Input 1.
Also, the function calls in a sample source file of your program contained in the archive file from the contest webpage is the same as these function calls.
C++17, C++20, C++23, C++26, C++17 (Clang), C++20 (Clang)