Company: ethos life_9oct
Difficulty: medium
Track Command Position Problem Description A network contains n nodes numbered 1 to n , and node 1 is the root. The network is a rooted tree: every node except the root has exactly one parent, given by the array par , and a node may have any number of children. The array par has length n : par[0] = -1 marks node 1 as the root, and for every node i with 2 <= i <= n , par[i - 1] is the parent of node i . A command sent by a node propagates through the network as follows: The sending node receives the command first. A node passes the command to its direct children in ascending order of their indices . Each child propagates the command through its own subtree by the same process before the next child receives it. Propagation stops when every node in the sender's subtree has received the command. You are given q queries. Query i is a pair [startNode, index] : if node startNode sends a command, which node is the index -th to receive it? If fewer than index nodes receive the command, th