Finding Liars
Time limit3sMemory limit128 MB
Given a circular chain of accusations among truth-tellers and liars with at most t liars, identify people who must be liars in every consistent assignment.
- Level
Medium6 of 10
- Topics
- Greedy, Simulation, Math
- Solved
- No attempts yet
Problem
There are people labeled . Each person is either a truth-teller or a liar, and the total number of liars is at most (with ).
Any person can test another person and report whether is a truth-teller or a liar. The outcome is if person reports that is a liar, and if person reports that is a truth-teller. A report is reliable exactly when the tester is a truth-teller; if the tester is a liar, the report is unreliable and may take either value. The outcomes are summarized below.
Testing is arranged in a circle: person tests person , person tests person , , person tests person , and person tests person . From the outcomes, some people are guaranteed to be liars, while others may or may not be liars. Given , , and the outcomes, determine which people are definitely liars.
For example, let , , and let the outcomes be . Person must be a liar: if person were a truth-teller, then following the reports forces persons , , and to be liars as well, giving at least three liars and contradicting . So person is a definite liar. However, both and are possible liar sets, so person cannot be pinned down as a definite liar.
You may assume the given outcomes come from some assignment that has at most liars.
Input
The first line contains the number of test cases . Each test case has two lines. The first line has two integers: (), the number of people, and (), the maximum number of liars. The second line has values, each or , giving in this order.
Output
For each test case, print one line with two integers: the number of definite liars, and the smallest label among the definite liars. If there are no definite liars, print as the second integer.