✅ C++ , Clean code | Graph + DFS | Easy Explanation with comments
C++\n\nclass Solution {\npublic:\n    \n     \n    // Steps : \n    // 1 - For each node, you need to find the sizes of the subtrees rooted in each of its child
**C++**\n```\nclass Solution {\npublic:\n    \n     \n    // Steps : \n    // 1 - For each node, you need to find the sizes of the subtrees rooted in each of its children.\n    \n    // 2 - How to determine the number of nodes in the rest of the tree? \n\t// Can you subtract the size of the subtree rooted at the node from the total number of nodes of the tree?\n    \n    // 3 - Use these values to compute the score of the node. Track the maximum score, and how many nodes achieve such score. \n    \n\t// calculating size of each subtree by standing at every node  \'0\' to \'n-1\'\n    int dfs(int src,vector<vector<int>>& g,vector<int>& size)\n    {\n         int ans = 1;// for curent node\n         for(auto child : g[src]){\n             ans += dfs(child,g,size);\n         }\n         return size[src] = ans; \n     }\n    \n    // This code can also be work for generalized tree not only for Binary tree\n    int countHighestScoreNodes(vector<int>& parents) \n    {    \n        int n=parents.size();\n        vector<int>size(n,0);  // size[i] indicates size of subtree(rooted at i node) + 1\n        vector<vector<int>>g(n);  // storing left and right child of a node\n        for(int i=1;i<n;i++){\n            g[parents[i]].push_back(i); // \'There is no parent for 0th node\'\n        }\n        \n        dfs(0,g,size); //calculating size of each subtree(rooted at ith node)\n\n        long long int maxCount = 0; // To avoid overflow  because perform product below you should take "long long int"\n        long long int maxScore = 0;\n        for(int i=0;i<n;i++) // Nodes from \'0\' to \'n-1\'\n        {\n            // calculate score of each node after removal their \'edge\' or \'node itself\'.\n            long long int product = 1;\n            product = max(product, (long long int)(n - size[i])); // calculating leftover nodes excluding child nodes \n            for(auto x : g[i])\n            {\n                product = product*size[x];\n            }\n            \n            if(product > maxScore){\n                maxScore = product;\n                maxCount = 1;\n            }\n            else if(product == maxScore){\n                maxCount++; // store count of nodes which have maximum score equal to "maxScore"\n            }\n        }\n            \n        return maxCount;\n    }\n};\n```\n**Hit the upvote if you like it : )**\n**Happy Coding**
['C']