Solution for Tree Generation