Java | O(n) | DFS | Concise
\n\nclass Solution {\n    long max = 0, res = 0;\n    public int countHighestScoreNodes(int[] parents) {\n        Map<Integer, List<Integer>> hm = new HashMap()
\n```\nclass Solution {\n    long max = 0, res = 0;\n    public int countHighestScoreNodes(int[] parents) {\n        Map<Integer, List<Integer>> hm = new HashMap();\n        for(int i = 0; i < parents.length; i++) {   // build the tree\n            hm.computeIfAbsent(parents[i], x ->new ArrayList<>()).add(i);\n        }\n        dfs(0, parents.length, hm); // traverse the tree to get the result\n        return (int)res;\n    }\n    int dfs(int s, int n, Map<Integer, List<Integer>> hm) {\n        int sum = 1;\n        long mult = 1L;\n        for(int child : hm.getOrDefault(s, new ArrayList<>())) {\n            int count = dfs(child, n, hm); // subtree node count\n            sum += count;\n            mult *= count; // multiply the result by children size\n        }     \n        mult *= (s == 0 ? 1L : n - sum); // multiply the result by remain size except self and children size(the nodes through parent)\n        if(mult > max) {\n            max = mult;\n            res = 1;\n        } else if (mult == max) {\n            res++;\n        }\n        return sum; // return the node count of the tree rooted at s\n    }\n}\n```
['Depth-First Search', 'Java']