Update p2.cpp

Implemented tree_sum function