← 返回 uber 的题目列表K-th Employee Receiving Data
类型:online_judge
K-th Employee Receiving Data
Employees form a rooted tree. The array boss describes reporting relationships:
boss[i] is the direct manager of employee i.
The Boss has value -1 in boss.
Employee IDs range from 0 to n - 1.
When an employee receives data, that employee receives it first, then sends it to direct reports in ascending employee-ID order. Each report recursively follows the same rule.
For each query [startNode, k], return the ID of the k-th employee receiving data when transmission starts at startNode. startNode itself is the first receiver. Return -1 if its subtree contains fewer than k employees.
Example
Input
6 3
-1 0 0 1 1 2
0 1
1 3
0 6
Output
0
4
5