Use -indexed arrays to avoid off-by-one errors. Make sure your timer starts at and increments correctly. Test your DFS on small trees (- nodes) and manually verify and values.
If those are wrong, everything breaks. For debugging, print the flattened array after building it. Check that subtree ranges make sense before building the segment tree. A good sanity check: tout[root] should equal if you use inclusive boundaries.