C++ Postorder traversal
IntuitionThe score of a node is the multiplication of the number of children on its right and his left and the tree which its parent belongs to.ApproachFirst cr
# Intuition

The score of a node is the multiplication of the number of children on its right and his left and the tree which its parent belongs to.


# Approach
First create an array Children which will have for each node a pair of left childe, right child.
Do a post order traversal of the Children array and for each node calculate the number of children (including itself) in the tree rooted at it. Then for traverse the tree from 1 to N. for each node find the number of children on the left, the right, and for the parent tree just use nodeCount[0] - nodeCount[i]
multiply them and store the score. 
Finally, sort the scores in decending order, and return how many have the highest count.

# Complexity
- Time complexity:
$$O(NLogN)$$

- Space complexity:
$$O(N)$$

# Code
```cpp []
class Solution {

    int getNodesCounts(int root, const vector<pair<int,int>>& ch, vector<int> &nodeCount){
        
        if(root == -1){
            return 0;
        }
        
        auto [ch1,ch2] = ch[root];

        int l = getNodesCounts(ch1,ch,nodeCount);
        int r = getNodesCounts(ch2,ch,nodeCount);

        nodeCount[root] = l + r + 1;
        return nodeCount[root];
    }

public:
    int countHighestScoreNodes(vector<int>& parents) {
       vector<pair<int,int>> children(parents.size(),{-1,-1});

       for(int i = 1; i < parents.size(); ++i){
            auto &[ch1, ch2] = children[parents[i]];
            if(ch1 == -1){
                ch1 = i;
            }else{
                ch2 = i;
            }
       }

        vector<int> nodeCounts(parents.size(),0);
        getNodesCounts(0,children,nodeCounts);

        vector<long long> scores(parents.size(),0);

        for(int i = 0; i < parents.size(); ++i){
            long long ch1Count = children[i].first == -1 ? 1 : nodeCounts[children[i].first];
            long long ch2Count = children[i].second == -1 ? 1 : nodeCounts[children[i].second];
            long long pcount = parents[i] == -1 ? 1 : nodeCounts[0] - nodeCounts[i];

            scores[i] = pcount* ch1Count * ch2Count;
        }

        sort(begin(scores),end(scores),[](const long long &i, const long long &j){
            return i > j;
        });

        long long topScore = scores[0];
        int result = 1;

        for(int i = 1; i < scores.size(); ++i){
            if(scores[i] != topScore){
                break;
            }

            result++;
        }

        return result;
    }   
};
```
['C++']