Here's how to build the Euler tour:
function eulerTour(root)
timer := 0
dfs(root, -1)
function dfs(v, parent)
tin[v] := timer
timer := timer + 1
tour[tin[v]] := v
for each child u of v (u ≠ parent)
dfs(u, v)
tout[v] := timer - 1
The tour array stores nodes in DFS order. For subtree of , indices contain exactly the nodes in 's subtree.