let define eulerian traversal tree connect undirected graph cycle follow consider depthfirst search algorithm traverse vertex tree enumerate order visit visit vertex count this function start vertex number 1 recursively run vertex connect edge current vertex visit increase number order formally describe function follow pseudocodenext_id 1id array length n fill 1visited array length n fill falsefunction dfsv visitedv true idv next_id next_id 1 neighbor v increase order visitedto dfstoyou give weight tree vertex enumerate integer 1 n algorithm describe aboveA leaf vertex tree connect vertex in tree give vertex 1 leaf the distance vertex tree sum weight edge simple path themyou answer q query follow type give integer v l r find short distance vertex v leave indice l r inclusive