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 with length in the range [k1,k2][k_1, k_2]. Both bounds are inclusive. The constraints are similar to Fixed-Length Paths I, so you need an O(nlog⁡n)O(n \log n) solution. Brute force checking all pairs and filtering by length will not work. Think about how to adapt the previous approach.

Instead of checking d1+d2=kd_1 + d_2 = k, what range should d2d_2 be in?

Space complexity is O(n)O(n) for the data structures used.