Trains the technique from
LeetCode 2477Minimum Fuel Cost to Report to the CapitalThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A park has n depots numbered 0 through n - 1, joined by n - 1 two-way tracks. roads[i] = [a, b] is a track between depot a and depot b, and the layout is such that exactly one route of tracks joins any two depots.
One warden waits at every depot other than depot 0, and every warden must reach depot 0, where the ranger station stands. Each of those depots also holds one van, and a van carries at most seats wardens.
Wardens travel by van along the tracks. A van burns one litre of fuel for each track it drives along. Wardens may change vans freely whenever they meet at a depot, and a van may be abandoned at any depot.
Return the least fuel, in litres, that gets every warden to depot 0.
Example 1
Each of the three wardens drives their own van straight along one track to depot 0, burning one litre each.
Example 2
The depots form a line 0-1-2-3-4. The track between depots 3 and 4 is driven once, the one between 2 and 3 once, the one between 1 and 2 twice, and the one between 0 and 1 twice, for six litres in total.
Example 3
A single warden drives one track, burning one litre.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def total_fuel(roads: list[list[int]], seats: int) -> int:public long totalFuel(int[][] roads, int seats)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.