Internet Monopoly

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

요약
연결 상태에서 간선이 온라인으로 추가될 때, 모든 최소 신장 트리가 정확히 K개의 저렴한 간선을 쓰도록 가격을 정할 수 있는지 판정한다.
난이도

어려움10점 중 8점

유형
그래프, 최소 신장 트리, 유니온 파인드, 동적 계획법
정답자
아직 제출이 없습니다

문제

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 100,000100\\,000 Euros; for the remaining cables it's 200,000200\\,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 100,000100\\,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 (1≤N≤3⋅1051 \le N \le 3 \cdot 10^5, 1≤Q≤4⋅1051 \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' (1≤U≤N1 \le U \le N, 1≤V≤N1 \le V \le N, U≠VU \ne V), each query of type 2 as '? KK' (0≤K≤M0 \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

  1. 예제 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