counting subtrees in c++