Graph Theory37 sections · 1633 units
Open in Course

Problem - Cat and Mouse (Part 8)

(Data structures needed)

You need three arrays: one for the outcome of each state, one for the degree of each state, and a queue for BFS. Initialize the queue with all terminal states.

Process states level by level, marking wins and losses as you go. The code structure is similar to topological sort with additional logic for tracking whose turn it is and checking win conditions. Time complexity is O(n2)O(n^2) states times the average degree, giving O(n3)O(n^3) in the worst case.