DFS| Straight Simple approach| faster than 95.74% of C++ online submissions
\n\nStep 1: Make tree from parent array.\n[you can learn how to make it from other resources like gfg]\nStep 2: Think how you traverse binary tree and hence you
![image](https://assets.leetcode.com/users/images/d534c859-fce6-4240-b019-0a7723dab477_1636388292.4804392.png)\n\nStep 1: Make tree from parent array.\n[you can learn how to make it from other resources like gfg]\nStep 2: Think how you traverse binary tree and hence you can have value for each node using DFS which you can store in value array.\n**Note:** if you are not able to get what is **c**, comment please!\nAlso value of product can be large thats why we use **long long**\n```\nclass Solution {\npublic:\n    struct Node{\n        int val;\n        Node *left,*right;\n        Node(int i){\n            val=i;\n            left=right=NULL;\n        }\n    };\n    long long int maxv=0;\n    int func(Node *root, vector<long long int>&val){\n        if(!root)return 0;\n        int n=val.size();\n        long long int l=func(root->left,val), r= func(root->right,val);\n        if(root->val==0){ //for root c is 0\n            if(l==0||r==0){\n            val[root->val]=(l==0?r:l);\n            }\n            else{\n                val[root->val]=l*r;\n            }\n            maxv=max(maxv,val[root->val]);\n        return l+r+1;\n        }\n        int c=n-l-r-1;\n        if(l==0&&r==0){\n            val[root->val]=c;\n        }\n        else if(l==0||r==0){\n            val[root->val]=(l==0?c*r:c*l);\n        }\n        else val[root->val]=c*l*r;\n        \n        maxv=max(maxv,val[root->val]);\n        return l+r+1;\n    }\n    int countHighestScoreNodes(vector<int>& parents) {\n        int n=parents.size();\n        vector<Node*>v(n,NULL);\n        for(int i=0;i<n;i++){\n            v[i]=new Node(i); //v[i] is pointer to node i\n        }\n        //now we will make tree\n        Node *root=NULL;\n        for(int i=0;i<n;i++){\n            if(parents[i]==-1){\n                root=v[i];\n            }\n            else if(v[parents[i]]->left==NULL){\n                v[parents[i]]->left=v[i];\n            }\n            else v[parents[i]]->right=v[i];\n        }\n        //now we will calculate value for each node\n        vector<long long int>val(n,0);\n        long long int f=func(root,val);\n        int ans=0;\n        for(int i=0;i<n;i++){\n            if(val[i]==maxv)ans++;\n        }\n        return ans;\n    }\n};\n```
['Depth-First Search', 'Recursion', 'C', 'Binary Tree']