문제
Tired of filtering through web search results targeted at other farm animals, the cows have decided to launch their own search engine. Unfortunately, with their severe lack of experience managing large software projects, the number of employees
In a desperate attempt to improve the managerial structure of their company, the cows have structured the company in the form of a binary tree, where each employee is responsible for managing two direct subordinates, designated as the "left" and "right" subordinates in keeping with the tree structure. In order to balance the managerial load on each employee, the cows have arranged the structure of their company tree so that for each employee E, the total number of employees in E's left subtree is either equal to or one greater than the total number of employees in E's right subtree.
Each employee has a distinct integer-valued ID in the range
Unfortunately, the cows have lost track of the exact value of
Here is an example of a possible interaction between your program and the grader:
YOUR PROGRAM: 1
GRADER: 4 3
YOUR PROGRAM: 4
GRADER: 2 0
YOUR PROGRAM: 3
GRADER: 0 0
YOUR PROGRAM: Answer 4
The tree corresponding to this interaction is
1
4 3
2
Note that it was not necessary to ask about the children of node 2, since we can deduce that there are no such children from the fact that node 4 has no right child.
Technical note: this problem is being graded by an interactive grader that is a new part of our grading system. If you experience any behavior that appears to be a problem on the technical side with the grader, please report it to [email protected]. We do not believe it should be necessary, but if your code seems to be frozen during grading, try adding commands to flush the output stream (e.g., fflush(stdout) or cout.flush()), in case there is unexpected buffering preventing your output from reaching the grader (if this does seems necessary to make your code work, please also send a note to [email protected] so we can fix the issue in the future).
[Problem credits: Brian Dean, 2015]