You are given a tree representing a company hierarchy. Each employee except the boss has exactly one direct supervisor. The tree is rooted at the boss. Answer queries: what is the lowest common ancestor of employees a and b?
In other words, who is their closest common supervisor in the hierarchy?
There are up to , employees and , queries. You need fast lookups. Binary lifting gives you per query after preprocessing.