Use a stack for path reconstruction