Determine the outcome of a two-player turn-based chase on a graph where each player moves optimally.
Cat and Mouse
You are given a finite graph and two players: a mouse and a cat. The mouse starts at one node, the cat starts at another node, and the players alternate turns. On each turn, the active player must move along one edge to a neighboring node. Both players play optimally.
The mouse wants to reach a designated target node before being caught. The cat wants to land on the mouse's node to catch it, or otherwise prevent the mouse from winning. The game may also end in a draw if neither side can force a win.
Your task is to determine the final outcome of the game from the given starting positions.
This is a state-based game on a graph: the result depends not only on the current positions, but also on whose turn it is and how both players can respond in the future.
Input Format
Input
- A graph represented by adjacency information.
- Starting node for the mouse.
- Starting node for the cat.
- A designated target or terminal winning condition for the mouse, if applicable to the formulation.
Output
- Return the outcome of the game from the initial state.
- The answer should indicate whether the mouse wins, the cat wins, or the game is a draw.
Output Format
Output
- One of the possible game outcomes for the initial state:
- mouse win
- cat win
- draw
Constraints
- The graph has a finite number of nodes.
- Players move only along existing edges.
- Both players use optimal play.
- The game state space is finite, so repeated states may imply a draw depending on the rules.
Example 1
Input
graph = [[1,2],[0,2],[0,1]], mouseStart = 0, catStart = 2
Output
draw
Explanation
On this triangle graph, neither side can force a decisive result from every optimal line of play, so the game can repeat states and end in a draw.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.