C++ | DP on Tree |  Easy solution  | DFS
Calculate size of subtree for each node using DFS\n Now we have to remove each vertex i* , there might be three possibility-\n        1. we remove leaf node\n  
* Calculate size of subtree for each node using DFS\n* Now we have to remove each vertex **i** , there might be three possibility-\n        1. we remove leaf node\n        2. we remove node having one child\n        3. we remove node having two child      \n```\nclass Solution {\npublic:\n    int countHighestScoreNodes(vector<int>& par) {\n        long long int n = par.size();\n        vector<long long int> adj[n];\n        for(long long int i=1;i<par.size();i++)\n        {\n            adj[par[i]].push_back(i);\n        }\n        vector<long long int>dp(n,0);\n        map<long long int,long long int>mp;\n        dfs(adj,0,-1,dp);\n        long long int ans = -1;\n        for(long long int i=0;i<n;i++)\n        {\n            long long int left , right , rem;\n            if(adj[i].size()==0)\n            {\n                left = 1;\n                right = 1;\n                rem = n-1;\n            }\n            if(adj[i].size()==1)\n            {\n                left = dp[adj[i][0]];\n                right = 1;\n                rem = n-1-left;\n                if(rem==0)\n                    rem=1;\n            }\n            \n            if(adj[i].size()==2)\n            {\n                 left = dp[adj[i][0]];\n                 right = dp[adj[i][1]];\n                 rem = n-1-left-right;\n                 if(rem==0)\n                     rem=1;\n            }\n            // cout<<left*right*rem<<" ";\n            mp[left*right*rem]++;\n        }\n        return mp.rbegin()->second;\n    }\n    \n    void dfs(vector<long long int>adj[] ,long long int src , long long int par , vector<long long int>&dp )\n    {\n        dp[src]=1;\n        for(auto xt : adj[src])\n        {\n            if(xt!=par)\n            {\n                dfs(adj,xt,src,dp);\n                dp[src]+=dp[xt];\n            }\n        }\n    }\n};\n```
['Dynamic Programming', 'Tree', 'Depth-First Search', 'C']