#P6989. [NEERC 2014] Epic Win!

[NEERC 2014] Epic Win!

题目描述

A game of rock-paper-scissors is played by two players who simultaneously show out their moves: Rock, Paper , or Scissors. If their moves are the same, it's a draw. Otherwise, Rock beats Scissors, Paper beats Rock, and Scissors beat Paper .

The described procedure can be repeated many times. In this problem, two Finite State Machines (FSMs) will compete in a series of rounds. (Formally speaking, by FSMs we mean Moore machines in this problem. )

An FSM for playing rock-paper-scissors has finitely many states. Each state is described by the following: what move the FSM will make in the upcoming round, and what will be the new state in case of its opponent playing Rock, Paper , and Scissors.

Fortunately, you know your opponent FSM -- the entire scheme except for one thing: you do not know the initial state of that FSM.

Your task is to design your own FSM to fight the given one. Your FSM must beat the opponent in at least 99%99\% of the first 11 billion rounds. That's what we call an epic win!

输入格式

The input file contains a description of the opponent FSM in the following format.

The first line contains an integer n(1n100)n (1 \le n \le 100) -- the number of states in the FSM. States are numbered from 11 to nn . Each of the following nn lines contains a description of the state: a character cic_{i} denoting the move made by FSM and integers ri,pi,sir_{i}, p_{i}, s_{i} denoting the next state in case of seeing Rock, Paper, or Scissors respectively (ci(c_{i} can be R, P, or S; 1ri,pi,sin1 \le r_{i}, p_{i}, s_{i} \le n

输出格式

Write to the output the description of your FSM in the same format.

The initial state of your FSM is the first state.

The number of states may not exceed 5000050 000 .

2
R 1 1 2
P 2 2 1

2
P 1 2 1
S 1 1 1

提示

Time limit: 1 s, Memory limit: 256 MB.