I record every visit in the full tour, including the return steps. For a tree with edges , , and , the tour is . This produces an array of length .
You can answer lowest common ancestor (LCA) queries by taking the node with minimum depth between the first visits of and in the tour. Store the depth alongside each visit and run a range minimum query (RMQ) on that depth array. With a sparse table, preprocessing is time and space, and each query is time.