Let if person is a truth-teller and otherwise. Let if person is a culprit and otherwise. We know .
Each statement is one XOR constraint between two variables.
Build a graph on the variables, with each statement giving a parity-labeled edge. A disjoint set union with parity detects contradictions. If any contradiction occurs, there is no possible state, so print -1.
Otherwise, flipping every variable in any connected component preserves every constraint. The component containing is fixed by ; all other components may be flipped independently. Hence, person is a culprit in every possible state exactly when is in the component of and . Check people in ascending order.
Time complexity: . Space complexity: .
Solution written by GPT6