Flattening a Rooted Tree