Lesson: when you need to count paths by distance or by any constraint, use Centroid Decomposition. It is the standard technique for path counting.
This problem counts paths of length k. Centroid splits the tree so you only count paths passing through each centroid (paths within one subtree are handled recursively). This avoids counting the same path twice.
If you see "count paths where." or "find paths with distance k," think Centroid Decomposition immediately. It is the most efficient approach for these problems.