Python3: clear and simple DFS solution
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def countHighestScoreNodes(self, parents: List[int]) -> int:
        n = len(parents)
        tree = defaultdict(list)

        for i, p in enumerate(parents):
            if p >= 0:
                tree[p].append(i)
        
        highest_score = 0
        highest_nodes = 0

        def update_score(node, score):
            nonlocal highest_score, highest_nodes
            if score > highest_score:
                highest_nodes = 1
                highest_score = score
            elif score == highest_score:
                highest_nodes += 1
            
        def visit(node): # return size of subtree rooted at node
            children = tree.get(node, [])
            score = 1
            sizes = 1
            for child in children:
                s = visit(child)
                score *= s
                sizes += s
            if n > sizes:
                score *= n - sizes
            update_score(node, score)
            return sizes

        visit(0)
        return highest_nodes




        
```
['Python3']