The Puzzle Game Luminous Met on His Adventure
Time limit4sMemory limit1024 MB
Given a grid of light and dark traps, decide whether all traps can be removed by pressing dark cells that flip their neighbors, and print a press order if so.
- Level
Medium7 of 10
- Topics
- Graph, Topological sort, Matrix
- Solved
- No attempts yet
Problem
The sorcerer Luminous, master of light and darkness, is on an adventure. Right now he is trapped in a labyrinth full of traps. He took a shortcut to escape quickly, and at that moment he ran into a trap field called a puzzle game.
He had a reason to escape fast, so he walked up to the trap field to solve the puzzle game. Then a loud noise sounded and a hologram appeared. It showed a shrinking timer and the message "Every skill you have is sealed except one." Luminous shouted "Anti Magic Shell!" but the cry went nowhere. In the end he had to choose between solving the puzzle and giving up the shortcut.
The puzzle game is played on an grid. Each cell holds a light trap or a dark trap. To pass safely, he must use skills to remove every trap on the grid.
The only skill Luminous has not had sealed is the Light Punishing Resonator. It can only target dark traps. When used, the targeted dark trap is removed, and the traps in the orthogonally adjacent cells have their types flipped.
The labyrinth holds an endless number of traps, so he must solve puzzles of this kind in total.
Given the state of each puzzle, determine whether Luminous can solve it, and if he can, show how.
Input
The input consists of several puzzles. The first line contains , the number of puzzles to solve. The state of each puzzle follows in order.
The first line of each puzzle contains and , the number of rows and columns, separated by a space.
The next lines each contain a string of length made of L and D. If the -th character of line is L, cell has a light trap. If it is D, cell has a dark trap.
Output
For each puzzle, print whether it can be solved, and if it can, print the method.
If Luminous can solve the puzzle, print Solve. The following lines list the cells where he must use the Light Punishing Resonator, in order, over lines. If the trap at row , column must be targeted by the -th use of the Resonator, print and separated by a space on line .
If he cannot solve the puzzle, print Run.
If several methods solve a puzzle, printing any one of them is enough.
Constraints
- In all puzzles, the sum of does not exceed .
Hint
TMI: Anti Magic Shell is Luminous's skill that creates a barrier which ignores severe status effects.