Implementation of Utopian Tree problem in C++