Given a tree T with N vertices, your task is calculating the number of the connected sub-tree of T, which has the same centroid as T.
In order to define the centroid, some integer value will be associated to every vertex. Let's consider the vertex k. If we remove the vertex k from the tree (along with its adjacent edges), the remaining graph will have only N-1 vertices and may be composed of more than one connected components. Each of these components is (obviously) a tree. The value associated to vertex k is the largest number of vertices contained by some connected component in the remaining graph, after the removal of vertex k. All the vertices for which the associated value is minimum are considered centroids.
A graph can have an arbitrary number of centroids. However,it can be proved that for trees, there are only two possibilities:
1. The tree has precisely one centroid.
2. The tree has precisely two centroids. In this case, the two centroids are adjacent.
Note that in case 2, we just consider that T has two centroids, you should only count the sub-tree which has the two same centroids as T.