Java | DFS
\nclass Solution {\n    int n;\n    ArrayList<Integer>[] tree;\n    long[] res;\n    public int countHighestScoreNodes(int[] parents) {\n        n = parents.len
```\nclass Solution {\n    int n;\n    ArrayList<Integer>[] tree;\n    long[] res;\n    public int countHighestScoreNodes(int[] parents) {\n        n = parents.length;\n        tree = new ArrayList[n];\n        for(int i = 0 ; i < n ; i++)tree[i] = new ArrayList<>();\n        \n        for(int i = 1 ; i < n ; i++){\n            tree[parents[i]].add(i);\n        }\n        \n        res = new long[n];\n        \n        depth(0);\n        long max = 0;\n        for(long v : res){\n             max = Math.max(max,v);\n        }\n        int count = 0 ;\n        for(long v : res) if(v == max) count++;\n        return count;\n    }\n    \n    \n    public int depth(int src){\n        int child = 1;\n        long ma = 1;\n        for(int nbr : tree[src]){\n            int sc = depth(nbr);\n            ma *= sc;\n            child += sc;\n        }\n        if(src != 0)\n            ma *= (n - child);\n        \n        res[src] = ma;\n        return child;\n    }\n}\n```
[]