To build an Euler tour, run DFS from the root. Maintain an array tour and a counter timer = 0. When you enter node v, set tour[timer] = v, record first[v] = timer, and increment timer. After visiting each child, record v again with timer++.
function eulerTour(v, d):
first[v] = timer
tour[timer] = v
tourDepth[timer] = d
timer += 1
for each child c of v:
eulerTour(c, d + 1)
tour[timer] = v
tourDepth[timer] = d
timer += 1
Time: . Space: for the arrays.