This is an interactive problem.
During this festival filled with sweet aromas, preparing the grand finale dessert—double-skin milk—has encountered one final challenge.
As the shop's most popular dessert, a perfect serving of double-skin milk requires the upper layer of cake and the lower layer of pudding to blend perfectly. In this magical flea kingdom, the energies of the two dessert layers intertwine, hidden within a complex network of cities.
The shop's two experienced dessert masters—dacake8 and dapudding8—have decided to put you to the test. They have hidden cake and pudding on the roads between cities, respectively. Only by consulting them and correctly identifying a city connected to your main shop (city $1$) by a road containing dessert can you successfully complete this grand finale of double-skin milk!
There are $n$ cities, with a road connecting every pair of cities. There are $n-1$ pieces of cake; the $i$-th piece is on the road connecting cities $u_{i,1}$ and $v_{i,1}$. There are $n-1$ pieces of pudding; the $i$-th piece is on the road connecting cities $u_{i,2}$ and $v_{i,2}$. The roads containing cake and the roads containing pudding form two trees, respectively.
Initially, you do not know the exact locations of the cake and pudding. You may make at most $\min(1000,\frac{n\times(n-1)}{2})$ queries to dacake8 and dapudding8:
Query dacake8 and dapudding8 about cities $u$ and $v$. Initially, the multiset $S$ is empty.
- dacake8 starts at city $u$, follows the path consisting of roads containing cake to city $v$, and adds the labels of the cities visited to the multiset $S$.
- dapudding8 starts at city $u$, follows the path consisting of roads containing pudding to city $v$, and adds the labels of the cities visited to the multiset $S$.
- The interaction library returns the multiset $S$.
You are in city $1$. After finishing your queries, you must give a city $u$ such that the road connecting cities $1$ and $u$ contains a type of dessert.
dacake8 and dapudding8 do not wish to make things difficult for you. They guarantee that the locations of the cake and pudding are fixed before any queries are made. In other words, the interaction library is non-adaptive.
Implementation Details
You do not need to, and should not, implement the main function.
You must include the header file milk.h in your source file milk.cpp and implement the following two functions:
void init(int c, int t);
- $c,t$ denote the subtask number and the number of test cases, respectively. $id=0$ indicates that this test point is an example.
- For each test point, the interaction library calls this function exactly once, when the program starts running.
int find(int c, int n);
- $c,n$ denote the subtask number and the number of cities, respectively.
- This function must return a positive integer $u$, specifying a city $u$ such that the road connecting cities $1$ and $u$ contains a type of dessert.
- For each test point, the interaction library calls this function exactly $t$ times.
You may make a query by calling the following function:
std::vector<int>query(int u, int v);
- $u,v$ specify the two cities $u$ and $v$.
- You must ensure that $1\le u,v\le n$ and $u\ne v$.
- This function returns the multiset $S$, whose meaning is given in the problem description.
- Let the size of the multiset $S$ be $m$. Then $1\le S_i\le n$ and $S_0\le S_1\le \ldots \le S_{m-1}$ hold.
- You must ensure that this function is called no more than $1000$ times during each call to
findby the interaction library.
Testing Your Program
Place milk.cpp, milk.h, and the attached grader.cpp in the same directory, and compile using C++17:
g++ grader.cpp milk.cpp -o milk -O2 -std=c++17
./milk < ex_milk1.in
For the compiled executable milk:
The first line of the input to the interaction library contains two nonnegative integers $id,t$, denoting the test point number and the number of test cases, respectively.
For each test case, the first line contains a positive integer $n$, denoting the number of cities. Each of lines $2\sim n$ contains two positive integers $u_{i,1}$, $v_{i,1}$; each of the next $n-1$ lines contains two positive integers $u_{i,2}$, $v_{i,2}$.
If the answers from all $t$ calls to find are correct, the interaction library outputs Correct! on the first line and Max queries used: Q on the second line, where $Q$ denotes the maximum number of calls to query over all test cases. If at least one answer is incorrect, it outputs Wrong answer.; if an interface call is invalid, it also reports the reason on the standard error stream.
Examples
Input 1
0 3 5 1 5 2 5 2 4 3 5 1 2 1 4 3 4 4 5 8 1 2 2 3 3 4 4 5 5 6 6 7 7 8 1 7 2 4 3 6 4 6 5 7 5 8 6 8 2 1 2 1 2
Output 1
Correct! Max queries used: 28
Note
Please note that the final test data do not include the examples.
In the diagrams, a red edge indicates that the road between the two cities contains a piece of cake, and a blue edge indicates that it contains a piece of pudding.
For the first test case, the trees formed by the roads containing cake and pudding are as follows:
For the second test case, the trees formed by the roads containing cake and pudding are as follows:
For the third test case, a single road may contain both cake and pudding.
Constraints
| Subtask number $c=$ | $t=$ | $n=$ | Special property | Points |
|---|---|---|---|---|
| $1$ | $6$ | $3$ | None | $1$ |
| $2$ | $7875$ | $5$ | None | $2$ |
| $3$ | $100$ | $8$ | None | $3$ |
| $4$ | $1$ | $10^5$ | $\text{A}$ | $5$ |
| $5$ | $5$ | $10^5$ | $\text{B}$ | $5$ |
| $6$ | $10^3$ | $100$ | $\text{C}$ | $1$ |
| $7$ | $5$ | $10^5$ | $\text{C}$ | $5$ |
| $8$ | $10^3$ | $100$ | $\text{D}$ | $5$ |
| $9$ | $5$ | $10^5$ | $\text{D}$ | $15$ |
| $10$ | $10^3$ | $100$ | $\text{E}$ | $5$ |
| $11$ | $5$ | $10^5$ | $\text{E}$ | $15$ |
| $12$ | $10^3$ | $100$ | $\text{F}$ | $5$ |
| $13$ | $5$ | $10^5$ | $\text{F}$ | $15$ |
| $14$ | $10^3$ | $100$ | None | $15$ |
| $15$ | $5$ | $10^5$ | None | $3$ |
Special property $\text{A}$: The locations of both cake and pudding are generated purely at random.
Special property $\text{B}$: The possible answer is guaranteed to be unique.
Special property $\text{C}$: Root both trees formed by the roads containing cake and pudding at city $1$. If each city has a directed edge to its parent city in each of the two trees, the resulting directed graph is a DAG.
Special property $\text{D}$: Root both trees formed by the roads containing cake and pudding at city $2$. If each city has a directed edge to its parent city in each of the two trees, the resulting directed graph is a DAG.
Special property $\text{E}$: The locations of the pudding are generated purely at random. The locations of the cake do not depend on those of the pudding.
Special property $\text{F}$: The two trees formed by the roads containing cake and pudding are two chains, both with city $1$ as their head.
In this problem, random tree generation is defined as using a random Prufer sequence.
Subtasks
If the answer returned by find is incorrect or the arguments to query are invalid, the score multiplier for that test point is $0$.
For subtasks $1,2,3$, if the number of queries exceeds $\frac{n\times(n-1)}{2}$, the score multiplier for that test point is $0$; otherwise, it is $1$.
For subtasks $4\sim 15$, let $Q$ denote the maximum number of calls to query over all test cases. The score multiplier $f(Q)$ is calculated according to the following table:
| Range of $Q$ | $f(Q)$ |
|---|---|
| $Q\le 100$ | $1$ |
| $100< Q\le 1000$ | $1-\log_{20}(\frac{Q}{100})$ |
| $Q>1000$ | $0$ |
The final score for a test point is its point value multiplied by the score multiplier, kept to three decimal places according to UOJ's real-valued score rules.
Time limit: $20\ \mathrm{s}$.
Memory limit: $512\ \mathrm{MiB}$.