Island Alliances
시간 제한5초메모리 제한1024 MB
섬 국가들의 병합 제안을 순서대로 처리하면서, 서로 불신하는 섬 쌍이 같은 국가에 속하지 않을 때만 병합을 승인한다.
문제
In a vast ocean there are islands numbered from to , 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 pairs of islands whose inhabitants distrust each other and refuse to be part of the same state.
The islanders have sent you proposals that you should process in order. The th proposal calls for the state containing island to merge with the state containing island . 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 , , and , the number of islands, the number of distrusting pairs of islands, and the number of proposals.
- lines, the th of which contains two integers and , where , , meaning that the inhabitants of islands and distrust each other. Each pair will be listed at most once.
- lines, the th of which contains two integers and , where , describing the th 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 th proposal, and are guaranteed to belong to different states.
출력
Output lines, where the th line should be "REFUSE" if the th proposal should be refused, or "APPROVE" if the th proposal should be approved.