Graph Theory37 sections · 1633 units
Open in Course

Read Statement

(Problem link)

Read the full problem at the link above. You need to count paths of length exactly kk, where length is the number of edges. Both endpoints count, so a path from uu to vv is one path. Constraints make brute force impossible.

With nn up to 200,000200,000, checking all pairs times out. You need a smarter approach that avoids examining every pair. Try to think about how centroids might help before continuing. What paths pass through a centroid?