Medium
,BFS
,DFS
,Graph
,Tree
2477. Minimum Fuel Cost to Report to the Capital
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.
Example 1:
Example 2:
Example 3:
Constraints:
n
<= 105roads.length
== n - 1
roads[i].length
== 2ai
, bi
< n
ai
!= bi
roads
represents a valid tree.seats
<= 105Yen-Chi ChenSun, Feb 12, 2023
Time:
Extra Space:
XD Feb 12, 2023
Yen-Chi ChenSun, Feb 12, 2023