Skip to content

Practice Minimum Fuel Cost to Report to the Capital

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2477
LeetCode Problem

Minimum Fuel Cost to Report to the Capital

Problem Statement

There is a tree (i.e., a connected, undirected graph with no cycles) structure country network consisting of n cities numbered from 0 to n - 1 and exactly n - 1 roads. The capital city is city 0. You are given a 2D integer array roads where roads[i] = [ai, bi] denotes that there exists a bidirectional road connecting cities ai and bi. There is a meeting for the representatives of each city. The meeting is in the capital city. There is a car in each city. You are given an integer seats that indicates the number of seats in each car. A representative can use the car in their city to travel or change the car and ride with another representative. The cost of traveling between two cities is one liter of fuel. Return the minimum number of liters of fuel to reach the capital city.

Source: Minimum Fuel Cost to Report to the Capital on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
roads = [[0,1],[0,2],[0,3]], seats = 5
Output
3

# Example 2

Input
roads = [[3,1],[3,2],[1,0],[0,4],[0,5],[4,6]], seats = 2
Output
7

# Example 3

Input
roads = [], seats = 1
Output
0

Constraints

1 <= n <= 10^5
roads.length == n - 1
roads[i].length == 2
0 <= ai, bi < n
ai != bi
roads represents a valid tree.
1 <= seats <= 10^5

Related LeetCode Problems

Practice more problems similar to Minimum Fuel Cost to Report to the Capital.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.