Easy and simple code || C++ || DFS || O(N) solution
Step-1 We build a undirected graph using parent array.\nStep -2 For each node we need the count of left and right subtree size so ans for a node will be  ( left
**Step-1** We build a undirected graph using parent array.\n**Step -2** For each node we need the count of left and right subtree size so ans for a node will be  ( **left subtree size * right subtree size * (total nodes -left subtree size -right subtree size**) to get this we will make a dfs call with the root which will visit all its child nodes and return the subtree sizes which we will keep on adding.\n**Step -3** return the current subtree size  (**left subtree size + right subtree size +1** ) .\n\nTC->O(N)     //Since we are visiting each nodes only once.\nSC->O(N)  //Visted array\n\n```\nint maxcnt=0;\nlong long maxans=-1;\nint total=0;\nint dfs(int src, vector<vector<int>>&g,vector<bool>&vis)\n{\n    vis[src]=true;\n    int sum=0;\n    long long temp=1ll;\n    for(auto ne:g[src])\n    {\n        if(vis[ne]==false)\n        {\n            int v1=dfs(ne,g,vis);\n            sum+=v1;                                               // Adding subtree size of all child nodes\n            if(v1!=0)temp=temp*v1;                        // multiplying subtree sizes\n        }\n    }\n    \n    sum+=1;                                                       //including current node in current tree size\n    if(total-sum>0)\n    {\n       temp=temp*(total-sum);                           //multiplying subtree size which is parent of current node\n    }\n    \n    if(temp>=maxans)\n    {\n        if(temp==maxans)maxcnt++;\n        else\n        {\n            maxans=temp;\n            maxcnt=1;\n        }\n    }\n    \n    return sum;                                      // returning size of current tree\n}\n\nclass Solution {\npublic:\n    int countHighestScoreNodes(vector<int>& parents)\n    {\n        int root=0;\n        int n=parents.size();\n        total=n;\n        vector<vector<int>>g(n);\n        for(int i=0;i<parents.size();i++)\n        {\n            if(parents[i]==-1)\n            {\n                root=i;\n            }\n            else\n            {\n                g[parents[i]].push_back(i);\n                g[i].push_back(parents[i]);\n            }\n        }\n        maxcnt=0;\n        maxans=-1;\n        vector<bool>vis(n,false);\n        dfs(root,g,vis);\n        return maxcnt;\n    }\n};\n```\n\n\n\nSimilar problem -[1519. Number of Nodes in the Sub-Tree With the Same Label](https://leetcode.com/problems/number-of-nodes-in-the-sub-tree-with-the-same-label/)\nLittle diff but same concept.\n\nPlease upvote if u like the post. It gives me motivation !!!
['Depth-First Search', 'C']