This problem asks for the lowest common ancestor of two employees. No updates, no subtree ranges, no path counting. Ancestor queries.
LCA with Binary Lifting is perfect. You preprocess the tree once in time, storing ancestors at powers of for each node. Then each LCA query takes .
With , queries, this runs comfortably within time limits. Naive per query would TLE.
Space complexity is for the data structures used.