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

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

Island Alliances

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

요약
섬 국가들의 병합 제안을 순서대로 처리하면서, 서로 불신하는 섬 쌍이 같은 국가에 속하지 않을 때만 병합을 승인한다.
난이도

보통10점 중 7점

유형
유니온 파인드, 그래프, 구현, 해시맵
정답자
아직 제출이 없습니다

문제

In a vast ocean there are nn islands numbered from 11 to nn, where each island constitutes a sovereign state.

However, the large number of states is making foreign policy a very complicated matter, so the inhabitants of the islands have decided to simplify things by joining into larger (but fewer) states. This endeavour has turned out to be easier said than done, because there are mm pairs of islands whose inhabitants distrust each other and refuse to be part of the same state.

The islanders have sent you qq proposals that you should process in order. The iith proposal calls for the state containing island a_ia\_i to merge with the state containing island b_ib\_i. If the two states contain a pair of islands whose inhabitants distrust each other the proposal should be rejected, but otherwise the proposal should be approved and all the islands in the two states will henceforth be part of the same state.

Please help the islanders figure out which proposals should be rejected and which should be approved!

입력

The input consists of:

  • One line with three integers nn, mm, and qq, the number of islands, the number of distrusting pairs of islands, and the number of proposals.
  • mm lines, the iith of which contains two integers u_iu\_i and v_iv\_i, where 1≤u_i,v_i≤n1 \leq u\_i,v\_i \leq n, u_i≠v_iu\_i \neq v\_i, meaning that the inhabitants of islands u_iu\_i and v_iv\_i distrust each other. Each pair (u_i,v_i)(u\_i, v\_i) will be listed at most once.
  • qq lines, the iith of which contains two integers a_ia\_i and b_ib\_i, where 1≤a_i,b_i≤n1 \leq a\_i,b\_i \leq n, describing the iith proposal. It is guaranteed that no proposal will ever call for a state to merge with itself, meaning that at the time when you receive the iith proposal, a_ia\_i and b_ib\_i are guaranteed to belong to different states.

출력

Output qq lines, where the iith line should be "REFUSE" if the iith proposal should be refused, or "APPROVE" if the iith proposal should be approved.

예제2

  1. 예제 1

    입력
    3 1 2
    1 2
    2 1
    1 3
    
    예상 출력
    REFUSE
    APPROVE
    
  2. 예제 2

    입력
    8 3 7
    1 2
    2 3
    3 4
    1 2
    4 5
    5 6
    7 8
    3 4
    1 3
    2 4
    
    예상 출력
    REFUSE
    APPROVE
    APPROVE
    APPROVE
    REFUSE
    APPROVE
    APPROVE