#P10440. [JOIST 2024] 环岛旅行 / Island Hopping
[JOIST 2024] 环岛旅行 / Island Hopping
Background
Due to some bugs, submitting with C++14 (GCC9) will cause a compilation error. Please use C++14 and other languages to submit.
This problem is translated from JOISC 2024 Day4 T2 「島巡り / Island Hopping」. Translation source: LOJ.
Do not include island.h. You should add the following declarations at the top of your file:
int query(int, int);
void answer(int, int);
The interactive files can be downloaded from the JOI official website.
Problem Description
This is an interactive problem. The interactive library for this problem is non-adaptive.
The JOI country has islands, numbered from to . There are routes, numbered from to . Route connects islands and bidirectionally. Starting from any island, you can reach any other island by traveling through some routes.
Aoi is going to travel in the JOI country. However, she does not know the routes in the JOI country. She plans to ask Bitaro, who lives in the JOI country, questions in the following way:
- Aoi tells Bitaro two integers and , where .
- Bitaro tells her the index of the -th closest island to among the other islands (excluding ). More precisely, he tells an integer such that is the -th smallest, where is the minimum number of routes used to travel from island to island .
Aoi wants to find out all routes in the JOI country by asking questions. Since she does not want to spend too much time, she can ask Bitaro at most questions.
Given the number of islands and the limit on the number of questions, write a program to simulate Aoi’s questioning strategy and determine all routes.
Implementation Details
You need to include the library island.h at the beginning of your program.
You need to implement the following function.
-
void solve(int N, int L)This function is called exactly once for each test case.
- The parameter
Nis the number of islands . - The parameter
Lis the question limit .
- The parameter
In your program, you can call the following functions.
-
int query(int v, int k)Aoi uses this function to ask Bitaro a question.
- The parameter
vmust be between and . Otherwise, your program will be judged Wrong Answer [1]. - The parameter
kmust be between and . Otherwise, your program will be judged Wrong Answer [2]. - The return value is the index of the -th closest island to among the other islands excluding . See the statement for the precise definition.
- You must not call
querymore than times. Otherwise, your program will be judged Wrong Answer [3].
- The parameter
-
void answer(int x, int y)Use this function to report one route in the JOI country.
- The parameters
xandyare two islands connected by a route. - The parameters
xandymust be between and . Otherwise, your program will be judged Wrong Answer [4]. - There must exist a route connecting islands
xandy. In other words, there must exist an integer such that or . Otherwise, your program will be judged Wrong Answer [5]. - Your program must not report the same route two or more times. Otherwise, your program will be judged Wrong Answer [6].
- The function
answermust be called exactly times. If, aftersolvefinishes, the number of calls to this function is not , your program will be judged Wrong Answer [7].
- The parameters
Notes
- You may implement other functions for internal use, or use global variables.
- Your program must not use standard input or standard output. Your program must not interact with other files in any way. However, your program may output debug information to standard error.
- The interactor used in the judging is not adaptive. This means the answer for each test case is fixed in advance.
Compilation and Execution
You can download the sample interactor in the attachments to test your program. The attached files also contain a sample program.
The sample interactor is the file grader.cpp. To test your program, put grader.cpp, island.cpp, and island.h in the same directory, and compile with the following command. You may also run compile.sh to compile your program.
g++ -std=gnu++20 -O2 -o grader grader.cpp island.cpp
If compilation succeeds, an executable file grader will be generated.
Note that the interactor used in the judging is different from the sample interactor. The sample interactor runs as a single process: it reads data from standard input and outputs results to standard output.
Input Format
The input format of the sample grader is as follows.
The first line contains two integers .
The next lines each contain two integers .
Output Format
The sample interactor will output the following information to standard output.
- If your program is judged correct, it will report the number of calls to
query, for example:Accepted: 2024. - If your program gets a certain Wrong Answer, the sample interactor will output its category, for example:
Wrong Answer [4].
If your program satisfies multiple Wrong Answer categories, the sample interactor will report only one of them.
4 16
1 2
2 4
4 3
5 25
5 2
3 1
1 4
1 5
Hint
Sample Interaction
Sample Interaction
The sample call process is shown in the table below.
| Call | Return value | |
|---|---|---|
solve(4, 16) |
||
query(2, 1) |
||
query(3, 1) |
||
answer(2, 4) |
||
query(2, 2) |
||
answer(2, 1) |
||
query(3, 2) |
||
query(2, 1) |
||
answer(3, 4) |
||
The minimum numbers of routes needed to travel from island to islands are , respectively. For example, to travel from island to island , we can use route and then route .
Sorting the islands by increasing gives islands . Therefore, the return value of query(2, 1) is , and the return value of query(2, 2) is .
Sample satisfies the constraints of subtasks .
Sample Interaction
The sample call process is shown in the table below.
| Call | Return value | |
|---|---|---|
solve(5, 25) |
||
query(1, 3) |
||
query(1, 4) |
||
answer(3, 1) |
||
query(2, 4) |
||
query(3, 1) |
||
query(3, 2) |
||
answer(1, 5) |
||
answer(4, 1) |
||
answer(2, 5) |
||
The minimum numbers of routes needed to travel from island to islands are , respectively. For example, to travel from island to island , we can use route and then route .
Sorting the islands by increasing gives islands . Therefore, the return value of query(1, 3) is , and the return value of query(1, 4) is .
Sample satisfies the constraints of subtasks .
Constraints
- You can travel through routes from any island to any other island.
Subtasks
| Subtask | Additional Constraints | Points |
|---|---|---|
| , each island has at most two incident routes | ||
| , each island has at most two incident routes | ||
| , island has three incident routes, each other island has at most two incident routes | ||
| , island has three incident routes, each other island has at most two incident routes | ||
Translated by ChatGPT 5