Internet Monopoly | 프로그래밍의 벗 PivotOJ
PivotOJ

Internet Monopoly

시간 제한: 1000ms메모리 제한: 1024MB출처: EIO 2021-22 openBOJ 29851

문제

There are NN cities in the Very Proud Kingdom, numbered 1,,N1, \ldots, N.

All the internet cables in the country are managed by Internet Operations Incorporated, or IOI. Internet service providers rent from IOI the right to use the cables.

The price list of IOI has the following structure: the yearly rent for some cables is 100000100\,000 Euros; for the remaining cables it's 200000200\,000 Euros. Each service provider always rents cables in such a way that all cities are connected to each other (possibly indirectly) by the rented cables and the total amount of rent is the lowest possible. IOI would like all renters to rent the exact same set of cables; this would make it easier for IOI to manage its cable network.

Every now and then, IOI lays new cables, and then the question arises: Is it possible to set the price list in such a way that exactly KK cables have the yearly rent equal to 100000100\,000 Euros, and it's quaranteed that all the renters will rent access to the exact same set of cables?

More formally, your program needs to process queries of the following types:

  • Given cities UU and VV. IOI lays a new cable between cities UU and VV.
  • Given KK. Determine whether it is possible to set the price list according to the conditions above.

In the beginning, before the first query, there are no cables in the country. You may assume that queries of the second type will only be given once all the cities in the country are connected to each other (possibly indirectly) by cables laid by IOI. You may also assume that IOI will never lay a cable between two cities where there already is a cable.

입력

The first line contains space-separated integers NN and QQ (1N31051 \le N \le 3 \cdot 10^5, 1Q41051 \le Q \le 4 \cdot 10^5), the number of cities and the number of queries, respectively.

The following QQ lines describe the queries. Each query of type 1 is given as '+ UU VV' (1UN1 \le U \le N, 1VN1 \le V \le N, UVU \ne V), each query of type 2 as '? KK' (0KM0 \le K \le M where MM is the number of cables laid by that time).

출력

Output answers to the queries of type 2, each answer on a separate line. If it is possible to set the price list, print 'JAH', otherwise print 'EI'.

예제

예제 1

입력
9 22
+ 1 2
+ 1 3
+ 2 3
+ 2 4
+ 3 4
+ 4 5
+ 5 6
+ 6 7
+ 5 7
+ 7 8
+ 7 9
? 0
? 9
? 3
? 2
? 6
? 5
? 7
? 1
? 10
? 4
? 11
출력
EI
EI
EI
EI
JAH
JAH
JAH
EI
EI
EI
EI
코드를 제출하려면 로그인하세요.