javascript dfs 372ms
\nconst initializeGraph = (n) => { let G = []; for (let i = 0; i < n; i++) { G.push([]); } return G; };\n\nlet g, n, res, cnt;\nconst countHighestScoreNodes = (
```\nconst initializeGraph = (n) => { let G = []; for (let i = 0; i < n; i++) { G.push([]); } return G; };\n\nlet g, n, res, cnt;\nconst countHighestScoreNodes = (parents) => {\n    res = -1, cnt = 0, n = parents.length, g = initializeGraph(n);\n    for (let i = 0; i < n; i++) {\n        if (parents[i] == -1) continue;\n        g[parents[i]].push(i);\n    }\n    dfs(0);\n    return cnt;\n};\n\nconst dfs = (x) => {\n    let subtree = 0, p = 1;\n    for (const child of g[x]) {\n        let tmp = dfs(child);\n        subtree += tmp;\n        p *= tmp;\n    }\n    if (subtree < n - 1) p *= n - 1 - subtree;\n    if (p > res) { // larger score comes, update res and reset cnt = 1\n        res = p;\n        cnt = 1;\n    } else if (p == res) { // equal largest score\n        cnt++;\n    }\n    return subtree + 1;\n};\n```
['Depth-First Search', 'JavaScript']