C++ post-order solution
\nGet the number of nodes of L subtree and R subtree. and score = l * r * rest. (if l, r, rest == 0 then set to 1)\n\nclass Solution {\npublic:\n    long long a
\nGet the number of nodes of L subtree and R subtree. and score = l * r * rest. (if l, r, rest == 0 then set to 1)\n```\nclass Solution {\npublic:\n    long long ans = 0;\n    long long cnt = 0;\n    vector<vector<int> > adj;\n    int n;\n    long long dfs(int node) {\n        long long l = 0, r = 0;\n        if(adj[node].size() >= 1) {\n            l = dfs(adj[node][0]);\n        }\n        if(adj[node].size() >= 2) {\n            r = dfs(adj[node][1]);\n        }\n        long long rest = n - 1 - r - l;\n        long long score = (l == 0 ? 1 : l) * (r == 0 ? 1 : r) * (rest == 0 ? 1 : rest);\n        if(score == ans) {\n            ++cnt;\n        }else if(score > ans) {\n            ans = score;\n            cnt = 1;\n        }\n        return l + r + 1;\n    }\n    int countHighestScoreNodes(vector<int>& parents) {\n        n = parents.size();\n        adj.resize(n);\n        for(int i = 1; i < parents.size(); i++ ){\n            adj[parents[i]].push_back(i);\n        }\n        dfs(0);\n        return cnt;\n    }\n};\n```\n\nWe can also use for-loop:\n```\n\nclass Solution {\npublic:\n    long long ans = 0;\n    long long cnt = 0;\n    vector<vector<int> > adj;\n    int n;\n    long long dfs(int node) {\n        long long rest = n - 1;\n        long long score = 1;\n        for(int child : adj[node]) {\n            long long subtreeCount = dfs(child);\n            rest -= subtreeCount;\n            score *= subtreeCount ? subtreeCount : 1;\n        }\n        score *= rest ? rest : 1;\n        if(score == ans) {\n            ++cnt;\n        }else if(score > ans) {\n            ans = score;\n            cnt = 1;\n        }\n        return n - rest;\n    }\n    int countHighestScoreNodes(vector<int>& parents) {\n        n = parents.size();\n        adj.resize(n);\n        for(int i = 1; i < parents.size(); i++ ){\n            adj[parents[i]].push_back(i);\n        }\n        dfs(0);\n        return cnt;\n    }\n};\n```
[]