hackerrank: Cut the tree