Calculate subtree size at every node
Calculate subtree size at every node.\nThen, score of a node = (product of size of subtree from every child) * (size of FULL tree - size of subtree at node).\n\
**Calculate subtree size at every node.**\nThen, score of a node = (product of size of subtree from every child) * (size of FULL tree - size of subtree at node).\n\n```\nclass Solution {\npublic:\n    int getSize(int cur, vector<int> children[], int subSize[]) {\n        subSize[cur] = 1;\n        \n        for(auto c : children[cur])\n            subSize[cur] += getSize(c, children, subSize);\n        \n        return subSize[cur];\n    }   \n    \n    int countHighestScoreNodes(vector<int>& parents) {\n        int n = parents.size();\n        int subSize[n];\n        vector<int> children[n];\n        \n        for(int i=0; i<n; i++) \n            if(parents[i]!=-1) children[parents[i]].push_back(i);\n        \n        getSize(0, children, subSize);\n        \n        long long int maxProduct = 0, ans = 0;\n        \n        for(int i=0; i<n; i++) {\n            long long int curProduct = max(n - subSize[i], 1);\n                // above condition given for root\n            for(auto c : children[i]) curProduct *= subSize[c];\n            \n            if(curProduct > maxProduct) {\n                maxProduct = curProduct;\n                ans = 1;\n            } else if(curProduct == maxProduct) ans++;\n        }\n        \n        return ans;\n    }\n};
[]