✔ Python3 Solution | DFS | O(n)
Complexity\n- Time complexity: O(n)\n- Space complexity: O(n)\n\n# Code\n\nclass Solution:\n    def countHighestScoreNodes(self, parents: List[int]) -> int:\n  
# Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution:\n    def countHighestScoreNodes(self, parents: List[int]) -> int:\n        n = len(parents)\n        scores = [1] * n\n        graph = [[] for _ in range(n)]\n        for e, i in enumerate(parents):\n            if e: graph[i].append(e)\n        def dfs(i):\n            res = 1\n            for j in graph[i]:\n                val = dfs(j)\n                res += val\n                scores[i] *= val\n            if i: scores[i] *= (n - res)\n            return res\n        dfs(0)\n        return scores.count(max(scores))\n```
['Python3']