Where Am I After K Jumps — Solution & Editorial
Binary lifting on the functional graph: up[j][v] = node after 2j jumps. Decompose K into its bits.
Complexity: O((N + Q) log K)
Binary lifting on the functional graph: up[j][v] = node after 2j jumps. Decompose K into its bits.
Complexity: O((N + Q) log K)