C++ Post-order Traversal
See my latest update in repo LeetCode\n\n## Solution 1. Post-order Traversal\n\nPost-order traverse the tree. For each node, calculate its score by multiplying 
See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1. Post-order Traversal\n\nPost-order traverse the tree. For each node, calculate its score by multiplying the node count of its left subtree, right subtree and nodes not in the current subtree (ignoring `0`). Count the nodes with the maximum score.\n\n```cpp\n// OJ: https://leetcode.com/contest/weekly-contest-264/problems/count-nodes-with-the-highest-score/\n// Author: github.com/lzl124631x\n// Time: O(N)\n// Space: O(N)\nclass Solution {\npublic:\n    int countHighestScoreNodes(vector<int>& P) {\n        long N = P.size(), ans = 0, maxScore = 0;\n        vector<vector<int>> G(N); // build the graph -- G[i] is a list of the children of node `i`.\n        for (int i = 1; i < N; ++i) G[P[i]].push_back(i);\n        function<int(int)> dfs = [&](int u) { // Post-order traversal. Returns the size of the subtree rooted at node `u`.\n            long score = 1, cnt = 1;\n            for (int v : G[u]) {\n                int c = dfs(v);\n                cnt += c;\n                score *= c;\n            }\n            long other = N - cnt; // The count of nodes not in this subtree rooted at node `u`.\n            if (other) score *= other;\n            if (score > maxScore) {\n                maxScore = score;\n                ans = 0;\n            }\n            if (score == maxScore) ++ans;\n            return cnt;\n        };\n        dfs(0);\n        return ans;\n    }\n};\n```
[]