#P14616. [2019 KAIST RUN Fall] Gosu 2
[2019 KAIST RUN Fall] Gosu 2
题目描述
Ho is an expert in martial arts called . She runs a Taebo school, and there are students in her school. To increase the inner competition inside the Taebo school, she is going to make a which assigns all students to a certain rank. To find a suitable rank, Ho made all pairs of students do a Taebo matchup with each other. In a Taebo matchup, exactly one person wins the match, and another person loses the match. The outcome of Taebo matchups may not be very simple: For example, there might be a case that student A beats B, B beats C, and C beats A. Such situation would make the ranking assignment pretty complicated as there is no definite winner from those three students.
To overcome the issue, Ho will find a and assign other students with respect to such a chain. A of length , is a sequence of different students such that beats if and only if . In other words, can beat all other students in the chain, can beat all other students in the chain except , can beat all other students in the chain except , and so on, and can beat no other student in the chain. Ho's website will assign other students based on such a chain, which will make the assignment easier.
Ho is not only an expert in Taebo, but she is a math genius too. Ho knows, that for any Taebo matchup, she can find the standard ranking chain of length , where is a base 2 logarithm. In other words, for any such that , Ho can find a standard ranking chain of such a length.
While Ho is very good at computer programming too, she is a little bit lazy, therefore she delegates her work to you. You should find a standard ranking chain of length exactly .
输入格式
In the first line, the number of test cases is given. For each test case, the following instances are given:
In the first line, the number of students is given.
In the -th line of the next lines, a string consisting of , , and , is given. Let's denote the -th character of as . is given as follows:
- , if .
- , if student won student .
- , if student won student .
- The sum of for all test cases does not exceed .
- ()
- If , then or . ()
- If , then . ()
- If , then . ()
输出格式
For each test case, print exactly integers in a single line, denoting the students in a standard ranking chain in the order of their skills. It can be proved that such a chain exists for every possible input.
5
1
-
2
-W
L3
-LW
W-L
LW4
-WLW
L-WL
WL-W
LWL5
-WLLW
L-LLW
WW-LL
WWW-W
LLWL
1
1 2
3 2
3 1 4
4 3 1
京公网安备 11011102002149号