| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 142 | 34 | 25 | 23.364% |
There are $N$ islands in JOI Kingdom, numbered from 1ドル$ to $N$. There are $N - 1$ sea routes in JOI Kingdom, numbered from 1ドル$ to $N - 1$. The sea route $j$ (1ドル ≤ j ≤ N - 1$) connects island $A_j$ and island $B_j$ bi-directionally. It is possible to travel from any island to any other island by using some sea routes.
Aoi is planning a trip in JOI Kingdom. However, she doesn’t know about sea routes in JOI Kingdom. She is going to ask questions with Bitaro, a citizen in JOI Kingdom, in the following way:
Aoi wants to know all sea routes in JOI Kingdom by asking questions to Bitaro. Since Aoi does not want to spend too much time, she can ask at most $L$ questions to Bitaro.
Write a program which, given the number of islands in JOI Kingdom and the limit on number of questions to Bitaro, implements Aoi’s strategy to find all sea routes.
You need to submit one file.
The file is island.cpp. It should implement the following function. The program should include island.h using the preprocessing directive #include.
void solve(int N, int L)
This function is called only once for each test case.
N is the number of islands $N$.L is the limit on number of questions $L$.In island.cpp, you can call the following function.
int query(int v, int k)
Using this function, Aoi asks question to Bitaro.
v must be between 1ドル$ and $N$. If not, your program is judged as Wrong Answer [1].k must be between 1ドル$ and $N-1$. If not, your program is judged as Wrong Answer [2].query more than $L$ times. If it is called more than $L$ times, your program is judged as Wrong Answer [3].void answer(int x, int y)
Your program answers a sea route in JOI Kindom by calling this function.
x and y are the numbers of two islands connected by a sea route.x and y must be between 1ドル$ and $N$. If not, your program is judged as Wrong Answer [4].x and y. In other words, there must exist an integer $j$ (1ドル ≤ j ≤ N - 1$) that x $= A_j$ and y $= B_j,ドル or x $= B_j$ and y $= A_j$. If not, your program is judged as Wrong Answer [5].answer must be called exactly $N-1$ times. If the number of calls of function answer is not $N - 1$ when the execution of function solve ends, your program is judged as Wrong Answer [7].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, island.cpp, island.h in the same directory, and run the following command to compile your programs. Instead, you may run compile.sh contained in the archive file.
g++ -std=gnu++20 -O2 -o grader grader.cpp island.cpp
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$ $L$
$A_1$ $B_1$
$A_2$ $B_2$
$\vdots$
$A_{N-1}$ $B_{N-1}$
Output for the Sample Grader
The sample grader outputs the following information to the standard output (quotes for clarity).
query as “Accepted: 2024”.Wrong Answer [4]”.If your program satisfies the conditions of several types of Wrong Answer, the sample grader reports only one of them.
The actual grader is not adaptive for all test cases. It means that the grader has a pre-determined answer for each test case.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 2 | $N = 3,ドル $L = 9$. |
| 2 | 4 | $L = N^2$. Each island has at most 2ドル$ connecting sea routes. |
| 3 | 7 | $L = 2N$. Each island has at most 2ドル$ connecting sea routes. |
| 4 | 9 | $L = N^2$. Island 1ドル$ has 3ドル$ connecting sea routes, and each of the other island has at most 2ドル$ connecting sea routes. |
| 5 | 13 | $L = 3N$. Island 1ドル$ has 3ドル$ connecting sea routes, and each of the other island has at most 2ドル$ connecting sea routes. |
| 6 | 15 | $L = N^2$. |
| 7 | 22 | $L = 3N$. |
| 8 | 28 | $L = 2N$. |
Here is a sample input for the sample grader and corresponding function calls.
| Sample Input 1 | Sample Function Calls | ||
|---|---|---|---|
| Calls | Calls | Return Values | |
4 16 1 2 2 4 4 3 |
solve(4, 16) |
||
query(2, 1) |
1 |
||
query(3, 1) |
4 |
||
answer(2, 4) |
|||
query(2, 2) |
4 |
||
answer(2, 1) |
|||
query(3, 2) |
2 |
||
query(2, 1) |
1 |
||
answer(3, 4) |
|||
The minimum number of sea routes to move from island 2ドル$ to islands 1ドル,ドル 3ドル,ドル 4ドル,ドル are 1ドル,ドル 2ドル,ドル 1ドル,ドル respectively. For example, to move from island 2ドル$ to island 3ドル,ドル we can use sea route 2ドル$ and then sea route 3ドル$.
Sorting the islands $i$ ($\ne 2$) in increasing order of $\text{dist}(2, i) \times N + i,ドル the result is island 1ドル,ドル island 4ドル,ドル island 3ドル,ドル in this order. Therefore, the return value of query(2, 1) is 1ドル,ドル and the return value of query(2, 2) is 4ドル$.
Sample Input 1 satisfies the constraints of Subtasks 2, 6. Among the files which can be obtained from the contest webpage, sample-01-in.txt corresponds to Sample Input 1.
| Sample Input 2 | Sample Function Calls | ||
|---|---|---|---|
| Calls | Calls | Return Values | |
5 25 5 2 3 1 1 4 1 5 |
solve(5, 25) |
||
query(1, 3) |
5 |
||
query(1, 4) |
2 |
||
answer(3, 1) |
|||
query(2, 4) |
4 |
||
query(3, 1) |
1 |
||
query(3, 2) |
4 |
||
answer(1, 5) |
|||
answer(4, 1) |
|||
answer(2, 5) |
|||
The minimum number of sea routes to move from island 1ドル$ to islands 2ドル,ドル 3ドル,ドル 4ドル,ドル 5ドル,ドル are 2ドル,ドル 1ドル,ドル 1ドル,ドル 1ドル,ドル respectively. For example, to move from island 1ドル$ and island 2ドル,ドル we can use sea route 4ドル$ and then sea route 1ドル$.
Sorting the islands $i$ ($\ne 1$) in increasing order of $\text{dist}(1, i) \times N + i,ドル the result is island 3ドル,ドル island 4ドル,ドル island 5ドル,ドル island 2ドル,ドル in this order. Therefore, the return value of query(1, 3) is 5ドル,ドル and the return value of query(1, 4) is 2ドル$.
Sample Input 2 satisfies the constraints of Subtasks 4, 6. Among the files which can be obtained from the contest webpage, sample-02-in.txt corresponds to Sample Input 2.
Both sample-01-in.txt and sample-02-in.txt can be used as inputs for the sample grader.
C++17, C++20, C++17 (Clang), C++20 (Clang)