Python (Simple DFS)
\n    def countHighestScoreNodes(self, parents):\n        dict1 = defaultdict(list)\n        \n        for node, parent in enumerate(parents):\n            dict
\n    def countHighestScoreNodes(self, parents):\n        dict1 = defaultdict(list)\n        \n        for node, parent in enumerate(parents):\n            dict1[parent].append(node)\n            \n        n, dict2 = len(parents), defaultdict(int)\n        \n        def dfs(node):\n            product, total = 1, 0\n            \n            for child in dict1[node]:\n                res = dfs(child)\n                product *= res\n                total += res\n                \n            product *= max(1, n-1-total)\n            \n            dict2[product] += 1\n            \n            return total + 1\n        \n        dfs(0)\n    \n        return dict2[max(dict2.keys())]\n
[]