Graph Theory37 sections · 1633 units
Open in Course

Codeforces 580C Kefa and Park - Logic

Updating the State

For each vertex, track the maximum consecutive cats seen on the path from root to that vertex. If you see a cat, increment the count. If you do not, reset it to zero.

Before recursing into a child, check if the consecutive cat count exceeds mm. If yes, do not explore that subtree. If no, continue.

At leaf nodes, check if you reached them without violating the cat limit. If yes, increment the restaurant counter.