

class Solution:
def minimumFuelCost(self, roads: List[List[int]], seats: int) -> int:
# 考虑每条边最少需要多少车
# 向上取整
# 考虑子树大小,向上的流量就是子树的大小
ans = 0
g = defaultdict(list)
for x, y in roads:
g[x].append(y)
g[y].append(x)
def dfs(x, fa): # 返回的是子树的size
size = 1
for child in g[x]:
if child != fa:
size += dfs(child, x)
if x: # 不统计root
nonlocal ans
ans += (size + seats - 1) // seats # size / seats 向上取整
return size
dfs(0, -1)
return ans