#P10545. Reconstructing the Initial Commands

    ID: 12564 Type: Default 1000ms 256MiB

Reconstructing the Initial Commands

Reconstructing the Initial Commands

You are given n robots arranged in a circle and numbered 0 to n-1 in counter‐clockwise order. Each robot has two hands. The i-th robot initially has its left hand pointing to robot \(l_i\) and its right hand pointing to robot \(r_i\). Moreover, each robot stores an initial command, which can be one of the following forms:

  • SLACKOFF: Does nothing. When executed, it outputs: "Robot i slacks off."
  • MOVE h z: Moves the h-th hand (0 for left, 1 for right) counter-clockwise by \(z\) positions. When executed, it outputs: "Robot i moves its left/right hand towards Robot j."
  • SWAP: Swaps the commands of the two robots pointed by its left and right hands. When executed, it outputs: "Robot i swaps the commands of Robot j and Robot k."
  • TRIGGER <COMMANDNAME>: <COMMAND>: This command is not executed directly. Instead, when some other robot finishes executing a command (meeting specific conditions) and its right hand points to this robot, the stored TRIGGER command will be triggered and its contained <COMMAND> will be executed. The conditions depend on whether COMMANDNAME is TRIGGER or not.
  • TOGGLETRIGGERREPLACE h <COMMANDNAME> <NEWCOMMAND>: Depending on whether the command of the robot pointed to by its h-th hand is a TRIGGER command or not, this command toggles that command between its TRIGGER and non-TRIGGER form. It then changes the executing robot's own command to <NEWCOMMAND>. When executed, it outputs: "Robot i toggles the trigger property of the command of Robot j."

You have executed a sequence of commands by choosing some robots (possibly repeatedly) and recorded the complete output from the execution. Note that after the last executed command output, no further trigger is pending. However, you have lost the order in which you selected the robots as well as the initial command stored in each robot. You only remember the number n and the initial hand pointers \(l_i\) and \(r_i\) for each robot. Your task is to reconstruct the initial command for each robot based solely on this information and the complete execution output.

Note: All formulas must be in LaTeX format. In this problem, you can assume that a valid reconstruction always exists. For the purpose of this task, a simple valid reconstruction is to assume that every robot’s initial command is SLACKOFF.

inputFormat

The input consists of multiple lines:

  1. The first line contains an integer \(n\) denoting the number of robots.
  2. The second line contains \(n\) space‐separated integers \(l_0, l_1, \dots, l_{n-1}\), where \(l_i\) is the index of the robot that the i-th robot's left hand points to.
  3. The third line contains \(n\) space‐separated integers \(r_0, r_1, \dots, r_{n-1}\), where \(r_i\) is the index of the robot that the i-th robot's right hand points to.
  4. The fourth line contains an integer \(m\) representing the number of lines in the complete execution output.
  5. The following \(m\) lines each contain a string representing an output line from a command execution. The outputs follow one of these formats:
    • Robot <id> slacks off.
    • Robot <id> moves its left/right hand towards Robot <id2>.
    • Robot <id> swaps the commands of Robot <id2> and Robot <id3>.
    • Robot <id> toggles the trigger property of the command of Robot <id2>.

outputFormat

Output \(n\) lines. The \(i-th\) line should contain the initial command of robot \(i\). For example, if every robot's command is SLACKOFF, print SLACKOFF on each line.

sample

3
0 0 0
1 1 1
3
Robot 0 slacks off.
Robot 1 slacks off.
Robot 2 slacks off.
SLACKOFF

SLACKOFF SLACKOFF

</p>