Minimum Fuel Cost to Report to the Capital

Medium · Graphs · about 25 minutes

Asked at Amazon, Google, Microsoft.

A tree of n cities (0 is the capital) is given by roads. Each city has one representative and one car with seats seats. Representatives travel toward the capital and can share cars along the way; each road traversal by a car costs one liter. Return the minimum total fuel.

Related guides