Beats 100% ---> Simple Approach
IntuitionThe goal is to calculate the number of nodes in the tree whose removal maximizes the product of the sizes of its disconnected components. This requires
# Intuition
The goal is to calculate the number of nodes in the tree whose removal maximizes the product of the sizes of its disconnected components. This requires traversing the tree, computing the product for each node's removal, and determining the maximum product and its frequency.

# Approach
1. **Tree Construction**:
   - Convert the `parents` array into a tree structure using `TreeNode` objects.
   - Each `TreeNode` object represents a node in the tree with references to its left and right children.

2. **Recursive Calculation**:
   - Implement a recursive function to traverse the tree and calculate the size of the subtree for each node.
   - During the traversal, calculate the product of the sizes of three components:
     - Left subtree
     - Right subtree
     - The remaining nodes excluding the current subtree

3. **Tracking Maximum Product**:
   - Keep track of the maximum product encountered.
   - Maintain a count of how many nodes yield the maximum product.

4. **Type Handling**:
   - Use `long long` to handle large intermediate product values and prevent overflow.

5. **Memory Management**:
   - Clean up dynamically allocated nodes to avoid memory leaks.

# Complexity

- **Time Complexity**:
  - Tree construction takes \(O(n)\).
  - Recursive traversal of the tree also takes \(O(n)\).
  - Overall time complexity is \(O(n)\).

- **Space Complexity**:
  - Space for the tree is \(O(n)\).
  - Recursive stack depth is \(O(h)\), where \(h\) is the height of the tree. In the worst case (skewed tree), \(h = O(n)\).

# Code
```cpp
class Solution {
public:
    class TreeNode {
    public:
        int val;
        TreeNode* left;
        TreeNode* right;

        TreeNode(int val) {
            this->val = val;
            this->left = nullptr;
            this->right = nullptr;
        }
    };

    int solve(TreeNode* root, long long& ans, int total, int& count) {
        if (!root) return 0;

        int left = solve(root->left, ans, total, count);
        int right = solve(root->right, ans, total, count);

        int rest = total - left - right - 1;
        int ret = left + right + 1;

        long long leftVal = max(static_cast<long long>(left), 1LL);
        long long rightVal = max(static_cast<long long>(right), 1LL);
        long long restVal = max(static_cast<long long>(rest), 1LL);

        long long currentScore = leftVal * rightVal * restVal;

        if (ans < currentScore) {
            ans = currentScore;
            count = 1;
        } else if (ans == currentScore) {
            count++;
        }

        return ret;
    }

    int countHighestScoreNodes(vector<int>& parents) {
        int n = parents.size();
        vector<TreeNode*> nodes(n);
        for (int i = 0; i < n; i++) {
            nodes[i] = new TreeNode(i);
        }

        for (int i = 1; i < n; i++) {
            if (!nodes[parents[i]]->left) 
                nodes[parents[i]]->left = nodes[i];
            else 
                nodes[parents[i]]->right = nodes[i];
        }

        long long ans = 0;
        int count = 0;
        solve(nodes[0], ans, n, count);

        for (auto node : nodes) {
            delete node;
        }

        return count;
    }
};
```
['C++']