Internet Monopoly
시간 제한1초메모리 제한1024 MB
연결 상태에서 간선이 온라인으로 추가될 때, 모든 최소 신장 트리가 정확히 K개의 저렴한 간선을 쓰도록 가격을 정할 수 있는지 판정한다.
문제
There are cities in the Very Proud Kingdom, numbered .
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 Euros; for the remaining cables it's 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 cables have the yearly rent equal to 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 and . IOI lays a new cable between cities and .
- Given . 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 and (, ), the number of cities and the number of queries, respectively.
The following lines describe the queries. Each query of type 1 is given as '+ ' (, , ), each query of type 2 as '? ' ( where 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'.