시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
5 초 | 512 MB | 0 | 0 | 0 | 0.000% |
On the distant isle of Googlia, there are two cities, Truthtown and Liarville. People from Truthtown always tell the truth and people from Liarville always lie. While exploring Googlia, you have run across a group of N inhabitants, and you want to figure out which city each one came from.
To make life simpler, you begin by numbering these people 1 through N. You then question each person, and record their M statements in the short-hand described below.
Short-hand | Meaning |
i T j | Person #i says, "Person #j is from Truthtown." |
i L j | Person #i says, "Person #j is from Liarville." |
i S j k | Person #i says, "Persons #j and #k are from the same city." |
i D j k | Person #i says, "Persons #j and #k are from different cities." |
Your task is to deduce which city each person came from. It is guaranteed that there will always be at least one solution.
For example, suppose you were given the following statements:
1 D 2 3
,1 D 2 4
,1 D 3 4
, and2 L 1
.
Then, you could reason as follows:
The first line of the input gives the number of test cases, T. T test cases follow. Each case begins with a line containing the integers N and M. The following M lines each contain a single statement from one inhabitant, formatted as described above.
For each test case, output one line containing "Case #x: y1 y2 ... yN", where x is the case number (starting from 1) and yi is a single letter indicating which city person #i is from:
2 4 4 1 D 2 3 1 D 2 4 1 D 3 4 2 L 1 3 1 1 S 1 2
Case #1: L T T T Case #2: - T -
Contest > Google > Google's Coding Competitions > Google Code Jam Africa 2010 > Online Competition D2번