When counting paths of length k through a centroid, you combine distances from different subtrees. For each node at distance d from the centroid in subtree A, you count nodes at distance k−d in other subtrees. This avoids double-counting paths within the same subtree.
Then you recurse on each subtree separately. Quiz: If the centroid has 3 children with subtrees of sizes 10, 15, and 20, how many times do you recurse after processing the centroid?