Graph Theory37 sections · 1633 units
Open in Course

Problem - Fixed-Length Paths I

(CSES, centroid decomposition)

You are given a tree with n nodes. Count the number of paths (u, v) such that the distance from u to v is exactly k edges. A path can start and end at any two nodes. The distance is the number of edges on the unique path between them in the tree.

There are up to 200200,000000 nodes and the path length k can be up to n. You need to count efficiently. Centroid decomposition is the standard technique for counting paths of a specific length in trees.