DFS
The value of a node is the product of:\n1. number of nodes in the left subtree, \n2. number of nodes in the right subtree,\n3. number of all other nodes, exclud
The value of a node is the product of:\n1. number of nodes in the left subtree, \n2. number of nodes in the right subtree,\n3. number of all other nodes, excluding the current one (n - left - right - 1)\n\nWe can just use DFS to count child nodes for (1) and (2), and we can then compute (3) as we know the total nubers of nodes.\n\n**C++**\n```cpp\nint dfs(vector<vector<int>> &al, vector<long long> &s, int i) {\n    long long prod = 1, sum = 1;\n    for (int j : al[i]) {\n        int cnt = dfs(al, s, j);\n        prod *= cnt;\n        sum += cnt;\n    }\n    s[i] = prod * (max(1ll, (long long)al.size() - sum));\n    return i != 0 ? sum : count(begin(s), end(s), *max_element(begin(s), end(s)));\n}\nint countHighestScoreNodes(vector<int>& p) {\n    vector<vector<int>> al(p.size());\n    vector<long long> s(p.size());\n    for (int i = 1; i < p.size(); ++i)\n        al[p[i]].push_back(i);\n    return dfs(al, s, 0);\n}\n```\n**Java**\n```java\nlong dfs(List<List<Integer>> al, long[] s, int i) {\n    long prod = 1, sum = 1;\n    for (int j : al.get(i)) {\n        long cnt = dfs(al, s, j);\n        prod *= cnt;\n        sum += cnt;\n    }\n    s[i] = prod * (Math.max(1, al.size() - sum));\n    return sum;\n}    \npublic int countHighestScoreNodes(int[] p) {\n    List<List<Integer>> al = new ArrayList<>();\n    for (int i = 0; i < p.length; ++i)\n        al.add(new ArrayList<Integer>());         \n    long[] s = new long[p.length];\n    for (int i = 1; i < p.length; ++i)\n        al.get(p[i]).add(i);\n    dfs(al, s, 0);\n    long max_val = Arrays.stream(s).max().getAsLong();\n    return (int)Arrays.stream(s).filter(v -> v == max_val).count();\n}\n```
['C', 'Java']