#P17271. [eJOI 2026] Reconstruct
[eJOI 2026] Reconstruct
题目描述
This is an interactive problem.
Bissy is about to enter the volunteer-organized orienteering game Final destination, where EJOI delegations compete to visit locations across the city. She is more interested in how the game was designed than in winning it.
There are locations and teams. Every team must visit all locations, and the teams have distinct starting locations: team starts from location . Each team receives its own route.
The routes are based on a hidden structure of fast public transport lines. The jury chose lines, each connecting two locations, so that every location is reachable from every other location. This structure is a tree. For every starting location , the jury generated an arbitrary DFS walk and assigned it as team 's route.
Bissy wants to discover the hidden tree. She may ask questions of the form:
What is the -th destination of team ?
Write find_tree to find the hidden tree.
A DFS walk of a tree is the order in which its vertices are first visited by depth-first search. Starting at a vertex , the procedure repeatedly moves recursively to an unvisited neighbor. When none remains, it returns to the previously visited vertex and continues.
:::align{center}
:::
In the figure, and the arrows show the steps of a DFS. The generated walk is . The order in which neighbors are visited matters; another possible walk is .
The tree and all DFS walks are fixed before your program starts and do not change in response to your questions. Different DFS walks may use different neighbor orders.
Implementation details
Implement:
std::vector<std::pair<int, int>> find_tree(int N)
- : the number of locations;
- return value: a list of tree edges. The order of the edges and the order of their endpoints do not matter.
For each test, this function may be called up to times.
To interact with the jury, call:
int guess(int i, int j)
It returns the -th location in the DFS walk starting at . In particular, guess(i, 0) returns . The function responds in constant time for subtasks through , and in logarithmic time for subtask . You must have ; otherwise, your solution receives Output isn't correct: Invalid call.
输入格式
Two sample graders are provided.
For local testing, Lgrader.cpp can be compiled with your program. It reads the number of test cases. For every case, it reads , then lines of edges, then lines of integers describing the DFS walks. Walk must start at vertex . Set AUTO_GENERATE to true to let the grader generate the walks. The grader reports an error if the result is incorrect; otherwise, it reports the number of queries for every test case and the overall maximum. This grader does not support sufficiently large , namely the constraints of subtask .
For system user tests, stub.cpp can be used with your program. Its input format is the same, but it has no built-in walk generation.
提示
Example
Assume the hidden public transport tree is:
:::align{center}
:::
For starting location , suppose the walk is . One possible interaction is:
| Participant program | Jury program |
|---|---|
find_tree(6) |
|
guess(0, 0) |
returns 0 |
guess(0, 1) |
returns 1 |
guess(0, 2) |
returns 2 |
guess(0, 3) |
returns 4 |
guess(0, 4) |
returns 3 |
guess(0, 5) |
returns 5 |
return {{0,1},{0,2},{4,0},{5,4},{3,4}}; |
The queries do not uniquely determine the tree, but this is the answer to the test in subtask .
Constraints
- Let be the maximum among calls in one test:
- if , then ;
- if , then ;
- if , then .
- The system grader may use up to 280 MiB, which counts toward your solution's memory.
Subtasks
| Subtask | Points | Additional constraints | |
|---|---|---|---|
| 0 | - | The example. | |
| 1 | 11 | - | |
| 2 | 6 | Every vertex is connected to at most two others. | |
| 3 | 13 | Every walk is generated by a DFS that always prioritizes moving away from vertex . If several such moves are possible, one is chosen arbitrarily. | |
| 4 | 11 | Every vertex other than is connected to at most two others. | |
| 5 | 10 | - | |
| 6 | 31 | ||
| 7 | 18 | ||
Scoring
For subtasks through , you receive full points if you find the tree within the time limit. For subtasks and , let be the maximum number of queries used on one subtest. The score fraction for a test is:
- if , then ;
- if , then ;
- if , then ;
- if , then .
For subtask , and . For subtask , and . The score fraction for the whole subtask is the minimum among all tests.
:::align{center}
:::