BFS Solution | Intuitive | Topological Sort Version
IntuitionStart with leaf nodes. As they dont have any out degree.Approach
Start with leaf node.
Count the children of nodes as u move above using topo sort algo
# Intuition
Start with leaf nodes. As they dont have any out degree. 

# Approach
1. Start with leaf node.
2. Count the children of nodes as u move above using topo sort algorithm with outdegree as O.
3. As you have count of children, just need to prod = (count of left children) * (count of right children) * (number of nodes left).

# Complexity
- Time complexity:
O(n)

- Space complexity:
O(n)

# Code
```cpp []
class Solution {
public:
    int countHighestScoreNodes(vector<int>& parents) {
        int cn=parents.size();
        unordered_map<int, int> mp;
        for(int i=0;i<cn;i++){
            // Map to store count of children of each parent. 
            mp[parents[i]]++;
        }
        queue<long long> q;
        for(int i=0;i<cn;i++){
            // Start with leaf node. They dont have outdegree.  
            if(mp[i]==0)q.push(i);
        }

        unordered_map<long long, pair<long long, long long>> v;
        for(long long i=0;i<cn;i++){
            // Keep count of left children & right children.  
            v[i]={0, 0};
        }

        unordered_map<long long, long long> ans;
        long long m=0;

        while(!q.empty()){
            int n=q.size();
            while(n-->0){
                // Take First node out with outdegree 0  
                long long node=q.front();q.pop();
                // If its 0 parent = -1, come out of loop 
                if(node==-1)break;
                long long t=0;
                
                // If node is not 0, prod of count of left & right children with number of nodes left. 
                if(node!=0)
                    t=(long long)(v[node].first==0?1:v[node].first)*(v[node].second==0?1:v[node].second)*(cn-v[node].first-v[node].second-1);
                
                // If node is 0, prod of count of left & right children is enough. 
                else
                    t=(v[node].first==0?1:v[node].first)*(v[node].second==0?1:v[node].second);
                
                m=max(m, t);
                // Keep count of maximum times m appears.  
                ans[t]++;
                

                // Storing count of children in parent v. (Order of left & right really doesnt matter  
                long long par = parents[node];
                 // Storing for left children first.  
                if(v[par].first==0)v[par]={v[node].first+v[node].second+1, v[par].second};
                // Storing for right children next.  
                else v[par]={v[par].first, v[node].first+v[node].second+1};
                
                mp[par]--;
                if(mp[par]==0)q.push(par);
            }
        }
        
        return ans[m];
    }
};
```
['Breadth-First Search', 'Topological Sort', 'Binary Tree', 'C++']