This page is still under construction.

Parts of this page are still being built. What you see may change.

Liars

Interview

Time limit1sMemory limit1024 MB

Summary
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 NN candidates who have drawn the numbers 11 through NN. 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 ii claims that candidate jj always lies,
  • candidate ii claims that candidate jj 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 NN and the number of statements MM collected by Bronius.

MM lines follow. The ii-th line contains three integers aia_i, bib_i, and mim_i describing the ii-th statement:

  • If mi=1m_i = 1, candidate aia_i claimed that candidate bib_i always lies.
  • If mi=0m_i = 0, candidate aia_i claimed that candidate bib_i always tells the truth.

The pairs (ai,bi)(a_i, b_i) in the input are unique; that is, candidate aia_i can make at most one statement about candidate bib_i.

Output

Print EGZISTUOJA if the described assignment into liars and non-liars exists, or NEEGZISTUOJA if it does not.

Constraints

  • 1≤N,M≤1000001 \le N, M \le 100000
  • 1≤ai≠bi≤N1 \le a_i \ne b_i \le N
  • 0≤mi≤10 \le m_i \le 1 (for 1≤i≤M1 \le i \le M)

Examples2

  1. Example 1

    Input
    5 5
    2 1 0
    3 2 0
    2 5 1
    3 4 1
    4 5 0
    
    Expected output
    EGZISTUOJA
    
  2. Example 2

    Input
    5 6
    2 1 0
    3 2 0
    2 5 1
    3 4 1
    4 5 0
    3 1 1
    
    Expected output
    NEEGZISTUOJA