Java with comments
Code\n\nclass Solution {\n    public int countHighestScoreNodes(int[] parents) {\n        int N = parents.length;\n\n        // Initialize adjacency list and su
# Code\n```\nclass Solution {\n    public int countHighestScoreNodes(int[] parents) {\n        int N = parents.length;\n\n        // Initialize adjacency list and subtree sizes array\n        List<List<Integer>> al = new ArrayList<>();\n        for (int i = 0; i < N; i++) {\n            al.add(new ArrayList<>());\n        }\n        long[] subtreeSizes = new long[N];\n\n        // Construct adjacency list\n        for (int i = 1; i < N; i++) {\n            al.get(parents[i]).add(i);\n        }\n\n        // Calculate subtree sizes using DFS\n        dfs(al, subtreeSizes, 0);\n\n        long maxSubtreeSize = Arrays.stream(subtreeSizes).max().getAsLong();\n        return (int)Arrays.stream(subtreeSizes).filter(size -> size == maxSubtreeSize).count();\n    }\n\n    // DFS function to calculate subtree sizes and update the array s    \n    private long dfs(List<List<Integer>> al, long[] subtreeSizes, int currNode) {\n        long productOfSizes = 1, sumOfSizes = 1;\n\n        // Traverse neighbors of the current node\n        for (int neighbor : al.get(currNode)) {\n            long neighborSize = dfs(al, subtreeSizes, neighbor);\n            productOfSizes *= neighborSize;\n            sumOfSizes += neighborSize;\n        }\n\n        // Update subtreeSizes array for the current node\n        subtreeSizes[currNode] = productOfSizes * Math.max(1, al.size() - sumOfSizes);\n\n        // Return the sum of subtree sizes\n        return sumOfSizes;\n    }\n}\n```
['Java']