#P7753. Winning Strategy in the Axis‐Aligned Line Game
Winning Strategy in the Axis‐Aligned Line Game
Winning Strategy in the Axis‐Aligned Line Game
In this game, at the start, N points are drawn on a coordinate system. The players take turns drawing lines, with Mirko moving first. The rules are as follows:
- On the first move, Mirko draws a line \(l_1\) that is parallel to one of the coordinate axes (i.e. horizontal or vertical) and passes through one of the \(N\) points.
- On the \(i\)th move (for \(i \ge 2\)), the current player draws a line \(l_i\) that is also parallel to one of the axes. However, \(l_i\) must pass through one of the \(N\) points that lies on the previously drawn line \(l_{i-1}\).
- No two lines drawn throughout the game may coincide.
The first player who cannot make a move loses.
Game reformulation: A key observation is that every drawn line is either horizontal (of the form \(y = c\)) or vertical (of the form \(x = c\)). In particular, note that if a horizontal line \(y=c\) is drawn then it passes through all points with that \(y\)-coordinate. In any subsequent move, if the previous line was horizontal, the only valid moves are to draw a vertical line through one of the points on that horizontal line (since drawing the same horizontal line is forbidden). Similarly, if the previous line was vertical, the next move must be a horizontal line.
This structure gives rise to a bipartite graph formulation. Let one partition be the vertical lines (unique \(x\)-coordinates from the given points) and the other be the horizontal lines (unique \(y\)-coordinates). An edge exists between a vertical line \(x = a\) and a horizontal line \(y = b\) if the point \((a, b)\) is among the given points. The game then becomes equivalent to the following:
Players alternatingly select an unused vertex from the opposite partition such that there exists an edge from the last chosen vertex. The twist is that once a line (vertex) has been chosen it cannot be chosen again. Mirko can start by picking any vertex from either partition. It turns out that in each connected component of this bipartite graph, if the two partitions are imbalanced (i.e. one partition has strictly more vertices than the other), then any vertex from the larger partition is a winning start. Otherwise, if every connected component is balanced, the second player (Slavko) can always win.
Given the \(N\) points, determine who has a winning strategy. Output Mirko if the first player has a winning strategy, or Slavko otherwise.
inputFormat
The first line contains an integer \(N\) (\(1 \le N\)). Each of the next \(N\) lines contains two integers \(x\) and \(y\), representing the coordinates of a point.
You may assume that all coordinates fit into a 32-bit signed integer.
outputFormat
Output a single line containing either Mirko or Slavko, indicating who has a winning strategy.
sample
1
1 1
Slavko
</p>