solving utopian tree problem