아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Voltage Drops

시간 제한1초메모리 제한1024 MB

요약
노드 쌍 사이에서 측정한 전위차들이 키르히호프 전압 법칙과 모순되지 않는지 판정한다.
난이도

보통10점 중 5점

유형
그래프, 유니온 파인드, DFS
정답자
아직 제출이 없습니다

문제

Juku is learning about electricity and circuits in physics class. He needs to make several measurements in a circuit. It is late and Juku is tired, so he is afraid that he might make mistakes when writing down the results. Juku knows that he can check the validity of measurements using Kirchhoff's voltage law and wants a program that would help him do so.

Kirchhoff's voltage law states that the sum of voltage rises and drops around any closed path has to equal zero. More precisely this means the following. Let us have a circuit with various components, the terminals (ends) of which are connected to nodes. Any number of component terminals can be connected to each node. By connecting a measurement device's (voltmeter's) test probes to two nodes we find out the difference in electric potential (in other words, voltage) between the two nodes. If potential is greater at the node connected to the positive probe than at the node connected to the negative probe, then the device will show a positive number, if it is the other way around, then a negative number, and if electric potential is equal at the two nodes then the result is zero. Kirchhoff's voltage law states that if we form some path consisting of those nodes that ends at the same node it starts from and add up all the rises and falls of electric potential along this path, then the result must be 00.

You're given a number of electric potential differences Juku measured between some number of pairs of nodes. Determine whether Juku's results agree with Kirchhoff's voltage law.

입력

The first line of the input contains two space-separated integers: number of nodes NN (1≤N≤1051 \le N \le 10^5) and the number of Juku's measurements MM (1≤M≤1051 \le M \le 10^5). Nodes are numbered 1…N1 \ldots N.

Each of the following MM lines contains three space-separated integers ii, jj and UU: ii and jj denote nodes (1≤i,j≤N1 \le i,j \le N) and UU the voltage Juku measured between nodes ii and jj in volts (−500,000≤U≤500,000-500\\,000 \le U \le 500\\,000) when the positive test probe of the voltmeter was connected to node ii and negative one to node jj.

출력

Write one line to output that contains a single word: JAH if Juku's measurements agree with Kirchhoff's voltage law (there are no contradictions) or EI if they do not agree.

예제2

  1. 예제 1

    입력
    3 3
    1 2 -3
    3 2 2
    3 1 5
    
    예상 출력
    JAH
    
  2. 예제 2

    입력
    4 5
    4 4 3
    1 2 3
    2 1 -3
    3 2 7
    3 1 5
    
    예상 출력
    EI