Polygraph (Small)
InterviewTime limit5sMemory limit512 MB
With at most 10 people, decide for each whether every satisfying assignment of truth-teller and liar types forces Truthtown, Liarville, or leaves it undecided.
- Level
Medium6 of 10
- Topics
- Brute force, Simulation, Implementation, Backtracking
- Solved
- No attempts yet
Problem
The distant island of Googlia has two cities. Everyone from Truthtown always tells the truth, and everyone from Liarville always lies. While exploring Googlia you meet inhabitants, and you want to work out which city each one comes from.
You first number these people from 1 to . You then question them one by one and record their statements in the shorthand below.
Deduce which city each person comes from. At least one assignment consistent with all the statements is guaranteed to exist.
For example, suppose the statements are 1 D 2 3, 1 D 2 4, 1 D 3 4 and 2 L 1. Then you can reason as follows.
- There are only two cities, so persons 2, 3 and 4 cannot all come from different cities.
- So at least one of person 1's claims is a lie.
- So person 1 is from Liarville, and every claim of person 1 is a lie.
- So persons 2, 3 and 4 all come from the same city.
- Person 2's claim is true, so person 2 is from Truthtown.
- So persons 3 and 4 are from Truthtown as well.
Input
The first line contains the number of test cases . test cases follow. The first line of each test case contains the integers and , separated by a space. The next lines each contain one statement from one inhabitant, written in the shorthand above.
Limits
- Within one statement, and are different.
Output
For each test case, print one line in the form Case #x: y1 y2 ... yN, where is the test case number starting from 1 and is a single character telling which city person comes from. Separate the characters with one space.
- If the statements imply that person must be from Truthtown, then is
T. - If they imply that person must be from Liarville, then is
L. - If the statements are not enough to decide, then is
-.