1function maxParty(happy, children) {
2 const n = happy.length;
3 const dp = Array.from({ length: n }, () => [0, 0]);
4 function dfs(u) {
5 dp[u][1] = happy[u];
6 for (const v of children[u]) {
7 dfs(v);
8 dp[u][0] += Math.max(dp[v][0], dp[v][1]);
9 dp[u][1] += dp[v][0];
10 }
11 }
12 dfs(0);
13 return Math.max(dp[0][0], dp[0][1]);
14}