DOJ logoDOJ
Problems
Recently added problemsSaved problemsWorkbooks
CategoriesDLCContestsGroupsTeamsBoard
Ranking
Solved Problem RankingStreak rankingDOJ Power ranking
Status
Call for TasksLoginRegister
DOJ logoDOJ

Community online judge with OI-style subtask scoring, Elo ratings, and Discord-backed certification.

Problems
ProblemsCategories
Community
ContestsRankingBoardNoticesHost an external contestGuide
Account
LoginRegisterJudge Status
Policy
Terms of ServiceDLC RulesPrivacyAPI documentationLanguage runtimesContest rank rewardsRating and performance
© 2026 DOJ
All rights reserved
Editorial

You're the Culprit!

Back to problem

Editorial

Let Ti=1T_i=1Ti​=1 if person iii is a truth-teller and Ti=0T_i=0Ti​=0 otherwise. Let Ci=1C_i=1Ci​=1 if person iii is a culprit and Ci=0C_i=0Ci​=0 otherwise. We know T1=1T_1=1T1​=1.

Each statement is one XOR constraint between two variables.

  • t=1t=1t=1: Ta⊕Cb=1T_a\oplus C_b=1Ta​⊕Cb​=.

Build a graph on the 2N2N2N 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 T1T_1T1​ is fixed by T1=1T_1=1T1​=1; all other components may be flipped independently. Hence, person ii is a culprit in every possible state exactly when is in the component of and . Check people in ascending order.

Time complexity: O((N+M)α(N))O((N+M)\alpha(N))O((N+M)α(N)). Space complexity: O(N)O(N)O(N).

Solution written by GPT6

1
  • t=2t=2t=2: Ta⊕Cb=0T_a\oplus C_b=0Ta​⊕Cb​=0.
  • t=3t=3t=3: Ta⊕Tb=1T_a\oplus T_b=1Ta​⊕Tb​=1.
  • t=4t=4t=4: Ta⊕Tb=0T_a\oplus T_b=0Ta​⊕Tb​=0.
  • i
    CiC_iCi​
    T1T_1T1​
    Ci⊕T1=0C_i\oplus T_1=0Ci​⊕T1​=0