#P17271. [eJOI 2026] Reconstruct

    ID: 19748 远端评测题 4000ms 1024MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>交互题Special JudgeeJOI(欧洲)树的遍历树论2026

[eJOI 2026] Reconstruct

Problem Description

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 NN locations and NN teams. Every team must visit all locations, and the teams have distinct starting locations: team ii starts from location ii. Each team receives its own route.

The routes are based on a hidden structure of fast public transport lines. The jury chose N−1N-1 lines, each connecting two locations, so that every location is reachable from every other location. This structure is a tree. For every starting location ii, the jury generated an arbitrary DFS walk and assigned it as team ii's route.

Bissy wants to discover the hidden tree. She may ask questions of the form:

What is the jj-th destination of team ii?

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 vv, the procedure repeatedly moves recursively to an unvisited neighbor. When none remains, it returns to the previously visited vertex and continues.

:::align{center} Example DFS walk :::

In the figure, v=4v=4 and the arrows show the steps of a DFS. The generated walk is [4,1,2,0,3,6,7,5][4,1,2,0,3,6,7,5]. The order in which neighbors are visited matters; another possible walk is [4,3,5,7,6,1,0,2][4,3,5,7,6,1,0,2].

The tree and all NN 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)
  • NN: the number of locations;
  • return value: a list of N−1N-1 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 TT times.

To interact with the jury, call:

int guess(int i, int j)

It returns the jj-th location in the DFS walk starting at ii. In particular, guess(i, 0) returns ii. The function responds in constant time O(1)O(1) for subtasks 00 through 66, and in logarithmic time O(log⁡N)O(\log N) for subtask 77. You must have 0≤i,j≤N−10\le i,j\le N-1; otherwise, your solution receives Output isn't correct: Invalid call.

Input Format

Two sample graders are provided.

For local testing, Lgrader.cpp can be compiled with your program. It reads the number TT of test cases. For every case, it reads NN, then N−1N-1 lines of edges, then NN lines of NN integers describing the DFS walks. Walk ii must start at vertex ii. 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 NN, namely the constraints of subtask 77.

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.

Hint

Example

Assume the hidden public transport tree is:

:::align{center} Hidden tree in the example :::

For starting location 00, suppose the walk is [0,1,2,4,3,5][0,1,2,4,3,5]. 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 00.

Constraints

  • 2≤N≤216+12\le N\le 2^{16}+1
  • Let Nmax⁡N_{\max} be the maximum NN among calls in one test:
    • if Nmax⁡≤9N_{\max}\le 9, then 1≤T≤1001\le T\le 100;
    • if Nmax⁡≤210+1N_{\max}\le 2^{10}+1, then 1≤T≤101\le T\le 10;
    • if Nmax⁡≤216+1N_{\max}\le 2^{16}+1, then 1≤T≤31\le T\le 3.
  • The system grader may use up to 280 MiB, which counts toward your solution's memory.

Subtasks

Subtask Points NN Additional constraints
0 - The example.
1 11 ≤9\le 9 -
2 6 ≤100\le 100 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 00. If several such moves are possible, one is chosen arbitrarily.
4 11 Every vertex other than 00 is connected to at most two others.
5 10 -
6 31 ≤210+1\le 2^{10}+1
7 18 ≤216+1\le 2^{16}+1

Scoring

For subtasks 00 through 55, you receive full points if you find the tree within the time limit. For subtasks 66 and 77, let Qmax⁡Q_{\max} be the maximum number of queries used on one subtest. The score fraction SS for a test is:

  • if Qmax⁡≤L1Q_{\max}\le L_1, then S=1.0S=1.0;
  • if L1<Qmax⁡≤L2L_1<Q_{\max}\le L_2, then S=0.4+0.6⋅L2−Qmax⁡L2−L1S=0.4+0.6\cdot\dfrac{L_2-Q_{\max}}{L_2-L_1};
  • if L2<Qmax⁡≤3L2L_2<Q_{\max}\le 3L_2, then S=0.2+0.2⋅3L2−Qmax⁡2L2S=0.2+0.2\cdot\dfrac{3L_2-Q_{\max}}{2L_2};
  • if 3L2<Qmax⁡3L_2<Q_{\max}, then S=0.2S=0.2.

For subtask 66, L1=3(210+1)=3075L_1=3(2^{10}+1)=3075 and L2=9(210+1)=9225L_2=9(2^{10}+1)=9225. For subtask 77, L1=3(216+1)=196611L_1=3(2^{16}+1)=196611 and L2=15(216+1)=983055L_2=15(2^{16}+1)=983055. The score fraction for the whole subtask is the minimum SS among all tests.

:::align{center} Scoring graphs for subtasks 6 and 7 :::