Manipulating the Torus Game
Time limit1sMemory limit1024 MB
Players alternately add edges to N tori without crossings; choose which tori to fill into spheres so the first player loses, or report impossible.
- Level
Hard9 of 10
- Topics
- Game theory, Math
- Solved
- No attempts yet
Problem
A torus is a donut-shaped figure with one hole, as shown below.

Two players play a graph game on tori. At the start, the surface of torus has vertices and no edges. The players take turns. On a turn, a player does the following:
- Chooses one torus in the game and moves its vertices freely. A vertex can only move along the surface of the torus. When a vertex moves, its connected edges move with it so that no connection breaks. Two different vertices can never occupy the same position.
- Adds one or more edges. An edge must lie on the surface of the torus and form a continuous path between its two endpoints. Any shape is allowed as long as this holds. Duplicate edges and loops are not allowed.
- Redraws any edges on the chosen torus. The connections between vertices must not change in this step.
After the action, if the torus where the action was performed has either of the following, the player who performed the action loses immediately.
- Two edges cross each other.
- A vertex lies on an edge.
However, these conditions do not cause a loss in the middle of an action.
You are the second player. Before the game starts, you manipulate the tori to win. A manipulation means choosing between 0 and tori and filling in their holes to turn them into spheres. A sphere can be chosen during the game. At the start, a sphere has the same number of vertices as the torus had before the manipulation.
When both players use optimal strategies, determine whether you can manipulate the tori so that the first player loses. If you can, output the method. If there are several methods, any one is accepted.
Input
The first line contains the number of tori (). The second line contains integers (), separated by spaces.
Output
If you can manipulate the tori so that the first player loses, print Y. Otherwise, print N.
If you print Y, print the number of manipulated tori on the next line. If that number is at least one, print their indices on the following line, separated by spaces. Each index must appear only once. The order does not matter.
Hint
The sizes of the tori and spheres can be proven not to affect the outcome of the game.