| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 512 MB | 20 | 4 | 4 | 21.053% |
Ahoy! Have you ever heard about pirates and their treasures? Bytie has found an old bottle while having a walk along the beach in Gdynia. The letter inside gives instructions on how to find a hidden treasure, but it is quite difficult to decipher. One thing Bytie knows for sure is that he needs to find two special points in the park nearby and the treasure will be in the middle of the path connecting them.
There are several trails in the park. Apart from that, the forest in the park is very dense, so only positions on the trails are reachable for human beings. The structure of the trails has an interesting property: for any two points lying on the trails there is a unique path connecting them. The path may lead along multiple trails, but it never visits any point more than once.
Bytie asked his friends for help in exploring the park. They will start the treasure hunt in some point of the park, located on one of the trails. They will explore the park in phases. In each phase, one of the friends chooses one point that was already explored and walks a number of steps from that point along a trail, visiting only points which were never reached by any of the friends before.
During the exploration, Bytie will be analysing the structure of the park carefully. From time to time, Bytie may guess the two special points which determine the location of the treasure. For each such guess, he wants to know the point located in the middle of the only path connecting them. Your task is to help Bytie in determining these middle points.
You should write a library which interacts with the grading program. The library should contain the following three functions which will be called by the grader (and any more functions if you like):
init — this function will be called exactly once, in the beginning of the execution. It is for you to initialize your data structures etc.
void init();path — stating that one of the friends explored a new path in the park. This function is for you to build your data structures representing trails.
void path(int a, int s);dig — asking where to dig for the treasure.
int dig(int a, int b);Your library may not read anything, neither from the standard input nor from any file, and may not write anything, neither to the standard output nor to any file. Your library may write to the standard error stream/file (stderr). You should be aware, however, that this consumes time during the execution of the program.
If you are writing in C/C++, your library may not contain the main function. If you are using Pascal, you have to provide a unit (see the sample programs on your disk).
The table below shows a sample sequence of calls to the functions and the correct results of the dig calls. The structure of the trails in the park corresponding to this example run is shown in the figure.
| Function call | Result | New points added |
|---|---|---|
init(); |
1 | |
path(1, 2); |
2, 3 | |
dig(1, 3); |
2 | |
path(2, 5); |
4, 5, 6, 7, 8 | |
dig(7, 3); |
5 | |
dig(3, 7); |
4 | |
path(1, 2); |
9, 10 | |
path(3, 3); |
11, 12, 13 | |
dig(10, 11); |
1 | |
path(5, 1); |
14 | |
dig(14, 8); |
6 | |
dig(2, 4); |
2 |
C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)