Fewest boosters to lift nodes

Write codeHard35 min

Your task

A fibre network runs out from a single head end and its layout is a tree. Node 0 is the head end and uplink[0] is -1. For every other node i, uplink[i] names the node it hangs off, always a smaller number. A booster placed on a node lifts the signal on that node and on every node within reach hops of it, counting hops along the fibre in either direction. Return the fewest boosters that leave every node lifted. uplink may be empty, in which case no boosters are needed, and reach may be 0. Serving the most unlifted nodes you can with each booster is not the fewest.

Examples

min_boosters(uplink: list[int], reach: int) -> int
Example 1
Inputmin_boosters([-1, 0, 1, 0, 3], 1)
Output2
Example 2
Inputmin_boosters([-1, 0, 0, 0], 1)
Output1