There are a total of four questions, the other three feeling is relatively simple, the first question records the number of words, but the number of words is more, so use map to engage. The second question traverses the tree, drawing the depth of each node in the tree. The third problem is to find a single LCA.
The most difficult problem is a thinking problem, give the number of N (n<=10^6), if there are two number A, B, to meet 2*a<=b, you can put the number a in the number B, each number can be a maximum of one number, ask the maximum number of numbers to be installed?
For a litchi:
Suppose now n=5
These 5 numbers are: 4 1 2 8 9
Let's first Order 1 2 4 8 9
Then the 1->2,4->8 is loaded with a maximum of two.
At this point it is easy to think of several greedy strategies, such as sorting, from the smallest start greedy, or from the biggest start greedy.
Here is a set of data to show that this greed is wrong.
N=4
1 2 4 7
N=4
3 5 10 20
And see how this problem should be thought.
First of all, to find a key property, after sorting, there must be a number of x, so that the optimal solution is loaded in the number on the left side of X, loading the number on the right side of X.
Next look at the picture.
201,600-degree Internship side