2 DFS | C++
\nclass Solution {\n    int dfs1(int node, int pre, vector<int> adj[], vector<int> &cnt) {\n        int c = 1;\n        for(int ad : adj[node]) {\n            i
```\nclass Solution {\n    int dfs1(int node, int pre, vector<int> adj[], vector<int> &cnt) {\n        int c = 1;\n        for(int ad : adj[node]) {\n            if(ad == pre) continue;\n            c += dfs1(ad, node, adj, cnt);\n        }\n        return cnt[node] = c;\n    }\n    void dfs2(int node, int pre, vector<int> adj[], vector<int> &cnt, int n, unordered_map<long long, int> &m) {\n        long long p = 1;\n        for(int ad : adj[node]) {\n            if(ad == pre) {\n                p *= n - cnt[node];\n                continue;\n            }\n            p *= cnt[ad];\n            dfs2(ad, node, adj, cnt, n, m);\n        }\n        m[p]++;\n    }\n\npublic:\n    int countHighestScoreNodes(vector<int>& parents) {\n        int n = parents.size(), ans;\n        long long mx = 0;\n        vector<int> adj[n];\n        for(int i=1; i<n; i++) adj[i].push_back(parents[i]), adj[parents[i]].push_back(i);\n\n        vector<int> cnt(n);\n        dfs1(0, -1, adj, cnt);\n        \n        unordered_map<long long, int> m;\n        dfs2(0, -1, adj, cnt, n, m);\n\n        for(auto i : m) {\n            if(i.first > mx) ans = i.second, mx = i.first;\n        }\n        return ans;\n    }\n};\n```
['Depth-First Search', 'C++']