DFS entry and exit times

Record when we enter and leave each branch of a tree. Later, those times let us check whether one folder sits inside another.

Read and advance the clock on arrival and departure. A child’s entire visit fits between its parent’s entry and exit.

Time is O(V). Testing ancestry using the timestamps takes O(1).