Graph Theory37 sections · 1633 units
Open in Course

Core Idea - Tree Structure

(Input is a tree)

The input gives you n1n-1 integers: the boss of employee 22, the boss of employee 33, and so on. Employee 11 is the CEO (root).

Build the tree by setting parent[i] to the given boss. Then build the upup table as described. Each query asks for up[v][?] where ?? is kk decomposed into powers of 22. No need to build an adjacency list for this problem. The parent array is all you need to fill the binary lifting table.