Two dfs O(n)
\nclass Solution {\npublic:\n    vector<vector<int>>adj;\n    vector<long long int>counter;\n    long long int res=0;\n    int countt=0;\n    void dfs(int src)\
```\nclass Solution {\npublic:\n    vector<vector<int>>adj;\n    vector<long long int>counter;\n    long long int res=0;\n    int countt=0;\n    void dfs(int src)\n    {\n        for(int i=0;i<adj[src].size();i++)\n        {\n            int u=adj[src][i];\n            dfs(u);\n            counter[src]+=counter[u];\n        }\n        counter[src]++;\n    }\n    \n    void dfs2(int src,vector<int>& parents)\n    {\n        long long int p=1;\n        for(int i=0;i<adj[src].size();i++)\n        {\n            int u=adj[src][i];\n            p=p*counter[u];\n\n            dfs2(u,parents);\n            \n            \n            \n        }\n        if(parents[src] != -1)\n        {\n            p=p*(counter.size()-counter[src]);\n\n        }\n       \n        \n        if(p > res)\n        {\n            res=p;\n            countt=1;\n        }\n        else if(p == res)\n        {\n            countt++;\n        }\n       \n        \n    }\n    \n    int countHighestScoreNodes(vector<int>& parents) {\n        int n=parents.size();\n        adj.resize(n);\n        int root;\n        for(int u=0;u<n;u++)\n        {\n            int v=parents[u];\n            if(v == -1)\n            {\n                root=u;\n                continue;\n            }\n            adj[v].push_back(u);\n        }\n        counter.resize(n,0);\n        dfs(root);\n\n        dfs2(root,parents);\n        return countt;\n        \n    }\n};\n```
[]