JAVA SOLUTION || HASHMAP || DFS || DP || EASY TO UNDERSTAND
\nclass Solution {\n    public int countHighestScoreNodes(int[] parents) \n    {\n        int total_nodes=parents.length;\n        \n        //stores parent nod
```\nclass Solution {\n    public int countHighestScoreNodes(int[] parents) \n    {\n        int total_nodes=parents.length;\n        \n        //stores parent node---> child nodes\n        Map<Integer,List<Integer>> parent_child=new HashMap<>();\n        for(int i=0;i<total_nodes;i++)\n        {\n            if(!parent_child.containsKey(parents[i]))\n            parent_child.put(parents[i],new ArrayList<>());\n            \n            List<Integer> temp=parent_child.get(parents[i]);\n            temp.add(i);\n            parent_child.put(parents[i],temp);\n        }\n        \n        \n        //count[i]=num of nodes with ith node as a subTree\n        int count[]=new int[total_nodes];\n        int x=1;\n        for(int i=0;i<total_nodes;i++)\n        {\n            if(count[i]==0)\n            x=fill_count_array(i,parent_child,count);\n        }\n        \n        \n        long max=0;int ans=0;\n        \n        for(int i=0;i<total_nodes;i++)\n        {\n            List<Integer> child=parent_child.get(i);\n            long curr=1;\n            \n            if(child!=null)\n            {\n              for(int j=0;j<child.size();j++)\n              curr=curr*(long)count[child.get(j)];\n            }\n            \n            if(parents[i]!=-1)\n            curr=curr*(long)(total_nodes-count[i]);\n            \n            \n            if(curr>max)\n            {\n                max=curr;\n                ans=1;\n            }\n            \n            else if(curr==max)\n            ans++;\n        }\n        \n        return ans;\n    }\n    \n    public int fill_count_array(int node,Map<Integer,List<Integer>> map,int count[])\n    {\n        if(count[node]!=0)\n        return count[node];\n        \n        List<Integer> child=map.get(node);\n        int total=1;\n        \n        if(child==null)\n        return count[node]=1;\n        \n        for(int i=0;i<child.size();i++)\n        {\n            total+=fill_count_array(child.get(i),map,count);\n        }\n            \n        count[node]=total;\n        return total;\n    }\n}\n```
['Dynamic Programming', 'Depth-First Search', 'Java']