root, and every employee has at most two direct reports. A node's value tells how much that person livens up the office party.
Nobody wants to party next to their *direct* boss, so an employee and their immediate manager may not both be invited. A boss's boss is fine.
Return the largest total liveliness you can get by choosing the guest list.root=tree_node([5, 1, 2, 4, 6, None, 3]) → 18
The best choice is 4, 6 and 3 (their bosses 1 and 2 stay home) plus the director 5: 5 + 4 + 6 + 3 = 18.
root=tree_node([2, 9, None, 1, 1]) → 9
The employee worth 9 outweighs everyone else combined: the director plus both of 9's reports give only 2 + 1 + 1 = 4 < 9.
root=tree_node([7]) → 7
root=tree_node([5, 1, 2, 4, 6, None, 3])
18
Run checks the first 3 tests in your browser. Submit checks all 94 tests on the server, hidden ones included.