Liars
InterviewTime limit1sMemory limit1024 MB
Given claims that candidate a says candidate b lies or tells the truth, decide whether candidates can be split into liars and truth-tellers consistently.
- Level
Medium6 of 10
- Topics
- Graph, BFS, Union-find, DFS
- Solved
- No attempts yet
Problem
In Bitland, parliamentary elections are approaching, which means political debates are being held on the national TV channel "Bit TV", featuring candidates who have drawn the numbers through . As he does every year, Bronius follows these debates very closely. He noticed that this year the following two kinds of statements were repeated especially often:
- candidate claims that candidate always lies,
- candidate claims that candidate always tells the truth.
Bronius wrote down all such statements and now wants to check whether they contradict one another.
We say the statements do not contradict one another if there exists an assignment of the candidates into liars and non-liars such that every statement made by a liar is false and every statement made by a non-liar is true.
Help Bronius determine whether such an assignment exists.
Input
The first line contains two positive integers: the number of candidates and the number of statements collected by Bronius.
lines follow. The -th line contains three integers , , and describing the -th statement:
- If , candidate claimed that candidate always lies.
- If , candidate claimed that candidate always tells the truth.
The pairs in the input are unique; that is, candidate can make at most one statement about candidate .
Output
Print EGZISTUOJA if the described assignment into liars and non-liars exists, or NEEGZISTUOJA if it does not.
Constraints
- (for )