Simple DFS backtracking solution
IntuitionTypical problem of backtracking. In the question the binary tree isn't given in the nodal form. Thus create graph#nodes=#nodes.left+#nodes.right+1Compl
# Intuition
Typical problem of backtracking. In the question the binary tree isn't given in the nodal form. Thus create graph

#nodes=#nodes.left+#nodes.right+1

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

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

# Code
```python3 []
class Solution:
    def countHighestScoreNodes(self, parents: List[int]) -> int:
        n=len(parents)
        graph=[[] for i in range(n)]

        for i in range(1,n):
            graph[parents[i]].append(i)

        def dfs(source,graph,res=None,visited=None):
            n=len(graph)
            
            if not res or not visited:
                res,visited=[1]*n,[False]*n
            
            if not graph[source]:
                return res

            visited[source]=True
            
            for i in graph[source]:
                if not visited[i]:
                    dfs(i,graph,res,visited)
                
                res[source]+=res[i]

            return res

        a=dfs(0,graph)
        res=[]
        kmax=0
        for i in range(n):
            left,right=1,1
            if graph[i]:
                left=a[graph[i][0]]
            if len(graph[i])==2:
                right=a[graph[i][1]]
            k=max(a[0]-a[i],1)*left*right
            kmax=max(k,kmax)
            res.append(k)
        x=0
        for i in range(n):
            if(kmax==res[i]):
                x+=1
        return x

        
        




            

            



            
                
```
['Python3']