Lowest common ancestor

Find the first place where the paths from two points towards the root meet. If the points are folders, this is their nearest shared folder.

Store ancestors one, two, four and more steps above each vertex. Equalize the depths, then lift both vertices together.

Preprocessing takes O(V log V), each query O(log V).