Python 3 | Graph, DFS, O(N)
\nclass Solution:\n    def countHighestScoreNodes(self, parents: List[int]) -> int:\n        n = len(parents)\n        graph: List[List[int]] = [[] for _ in ran
```\nclass Solution:\n    def countHighestScoreNodes(self, parents: List[int]) -> int:\n        n = len(parents)\n        graph: List[List[int]] = [[] for _ in range(n)]\n\n\n        for idx, val in enumerate(parents):\n            if val == -1:  \n                continue\n            graph[idx].append(val)\n            graph[val].append(idx)\n\n        def dfs(node: int, parent: int) -> int:\n            cnt = 1  \n            for child in graph[node]:\n                if child != parent:\n                    cnt += dfs(child, node)  \n                    subtree[node].append(child)\n            res[node] = cnt\n            return cnt  \n\n        res: Dict[int, int] = defaultdict(int)\n        subtree: Dict[int, List] = defaultdict(list)\n\n        dfs(0, -1)\n\n        maxList = [\n            (res[0] - res[i]) * math.prod([res[val] for val in subtree[i]])\n            if i != 0 else math.prod([res[val] for val in subtree[i]])\n            for i in range(n)\n        ]\n\n        mx = max(maxList)\n        ans: int = 0\n        for val in maxList:\n            if val == mx:\n                ans += 1\n\n        return ans\n```
['Depth-First Search']