#P14762. [Opoi 2025] CCD 的长恨歌
[Opoi 2025] CCD 的长恨歌
Background
A few days ago One year ago, CCD lost points in a mock contest and got mocked by Eriri, so he decided to make a problem to mock Eriri back.
The emperor loved beauty and longed for a lady who could topple a nation, yet after ruling for many years he could not find one.
In the Jiang family there was a girl just grown up, kept in the inner chambers, unknown to others.
Born with natural beauty that could not be ignored, one day she was chosen to stand by the ruler.
Looking back with a smile, a hundred charms appeared; the makeup of the six palaces all lost their color.
[upd 2025/5/5]. <- The link was deleted by Eriri the day before the contest…
Problem Description
Please note: this problem only supports submissions in C++11 or above.
Emperor Dong has a very mysterious rooted tree with nodes, with root .
And you, as the noble Consort Jiang, really want to know the shape of tree . However, each time you can only ask Emperor Dong one ordered pair , and he will tell you the lowest common ancestor of these two nodes in the tree. Since Emperor Dong is also busy preparing for Opoi, he only allows you to ask questions.
Luckily, Emperor Dong likes compact structures, so the number of leaves of this tree is at most .
This is an interactive problem.
When submitting, please add the following function declaration in your program:
int LCA(int,int);
This allows you to call LCA(x,y) and get their LCA.
You do not need to, and should not, implement the main function. You only need to implement the following function:
vector<pair<int, int> > guess(int n);
- For each test point, the interactive library will call this function only once.
- Here, is the number of nodes of the tree to be guessed this time.
- The returned vector describes the structure of tree . Each
pair<int, int>in thevectorrepresents an edge of the tree. There is no requirement on the order of the two nodes in each edge, nor on the order of the edges. - The time complexity of a single
LCA(x, y)call is strictly , and the interactive library preprocessing complexity is . - The SPJ will not return
WAbecause you called LCA too many times, but if you exceed calls, then all subsequent LCA call results will be-1.
There is a sample template template.cpp in the attachments. Using it, you can get a good score of points.
Output Format
Hint
Sample Explanation
| You | Interactor |
|---|---|
LCA(1,2) |
1 |
1 2 |
Accepted |
Besides the sample output, outputting 2 1 is also a valid solution.
Constraints and Conventions
For of the testdata, .
Partial score: there are groups of testdata in total. For the -th group, it is guaranteed that the number of leaves of the tree is at most .
2
1 2
Hint
Sample Explanation
| You | Interactor |
|---|---|
LCA(1,2) |
1 |
1 2 |
Accepted |
Besides the sample output, outputting 2 1 is also a valid solution.
Constraints and Conventions
For of the testdata, .
Partial score: there are groups of testdata in total. For the -th group, it is guaranteed that the number of leaves of the tree is at most .
Hint
If you do not know how to solve interactive problems, you can refer to this problem.
The template program and the template interactive library for this problem can be found in the attachments: template.cpp and s_interactor.cpp.
Translated by ChatGPT 5