#P6691. Consistent Multiple Choice Puzzle
Consistent Multiple Choice Puzzle
Consistent Multiple Choice Puzzle
This problem involves a self-referential multiple choice question with \(n\) options. For each option \(i\) (1-based index), its content is given in the following form:
+ Option \(a_i\) is correct/incorrect
A legal answer is an assignment of truth values (correct/incorrect) to all \(n\) options (each option can be marked either correct or incorrect) such that for every \(i\) (\(1\le i\le n\)) the statement in the \(i\)th option holds. In other words, if the \(i\)th option states
\(\text{Option } a_i \text{ is correct}\) then in your assignment, the \(a_i\)th option must be marked correct; if it states
\(\text{Option } a_i \text{ is incorrect}\) then the \(a_i\)th option must be marked incorrect.
Note that different options may impose conditions on the same option. If conflicting conditions occur for any option then no legal assignment exists.
If a legal assignment exists, let \(F\) be the number of options whose value is fixed by the constraints, and let \(T_f\) be the number of options fixed as correct. The remaining \(n-F\) options can be assigned arbitrarily, yielding \(2^{n-F}\) legal answers. Among these legal assignments, the minimum number of correct options is \(T_f\) (if all free choices are marked incorrect) while the maximum is \(T_f + (n-F)\) (if all free choices are marked correct).
Your task is to determine:
- the total number of legal answers,
- the maximum number of correct options among these legal answers, and
- the minimum number of correct options among these legal answers.
If no legal assignment exists, output No answer
.
inputFormat
The first line contains a single integer \(n\) (the number of options). Each of the following \(n\) lines contains an integer and a string separated by space. The integer \(a_i\) (\(1 \le a_i \le n\)) indicates the option which the \(i\)th statement refers to, and the string is either true
(indicating 'correct') or false
(indicating 'incorrect').
outputFormat
If a legal assignment exists, output three space-separated integers: the total number of legal answers, the maximum number of correct options among those answers, and the minimum number of correct options among those answers.
If no legal assignment exists, output No answer
.
sample
3
2 true
3 false
1 true
1 2 2