Easy C++ Solution || DFS || GRAPH
Intuition\nSince TreeNode class is not previously declared so it is a hint we dont need that. It is just a simple problem of graph and selecting the maximum.\n\
# Intuition\nSince TreeNode class is not previously declared so it is a hint we dont need that. It is just a simple problem of graph and selecting the maximum.\n\n# Approach\nCreate adjacency matrix and take the product of the components after disconnection. If its is max update max and reset count to 1, else update count.\n\n# Complexity\n- Time complexity:\nO(n)-->Since we are iterating each nodes only once.\n\n- Space complexity:\nO(n)-->For creating adjacency matrix.\n\n# Code\n```\nclass Solution {\npublic:\n    int n;\n    long long maxi=-1, count=0;\n    int solver(vector<vector<int>>& adj, int node) {\n        long long score = 1;\n        int childs = adj[node].size();\n\n        int leftNodes = 0, rightNodes = 0;\n        if (childs > 0) leftNodes = solver(adj, adj[node][0]);\n        if (childs > 1) rightNodes = solver(adj, adj[node][1]);\n\n        if (leftNodes > 0) score *=leftNodes;\n        if (rightNodes > 0) score *=rightNodes;\n\n        int parentNodes = n-leftNodes-rightNodes-1;\n        if (parentNodes > 0) score *= parentNodes;\n\n        if (score > maxi) {\n            maxi = score;\n            count = 1;\n        }\n\n        else if (score == maxi) count++;\n\n        return leftNodes + rightNodes + 1;\n    }\n    int countHighestScoreNodes(vector<int>& parents) {\n        n = parents.size();\n        vector<vector<int>> adj(n);\n        for (int i=1; i<n; i++) {\n            adj[parents[i]].push_back(i);\n        }\n\n        solver(adj, 0);\n        return count;\n    }\n};\n```
['C++']