#P10648. [NordicOI 2023] Island Alliances
[NordicOI 2023] Island Alliances
Background
Translated from NordicOI 2023 Problem C Island Alliances.
Problem Description
There are islands on the sea. Among them, there are pairs of islands that have a hostile relationship. However, because the weather is harsh, an island cannot survive alone, so some islands propose forming “alliances”.
There are alliance requests. Each request contains a pair , meaning that island wants to form an alliance with island . However, due to hostile relationships, this proposal may not be accepted. If none of the islands in the alliance that originally contains has a hostile relationship with any of the islands in the alliance that contains , then the two sides can agree to form an alliance; otherwise, they will refuse.
Note that once the alliance is approved, the two alliances are immediately merged into a single alliance.
Input Format
The first line contains three integers , , and , meaning there are islands, hostile pairs of islands, and proposals.
The next lines each contain a pair of integers , meaning island and island are hostile to each other.
Then the next lines each contain two integers and , meaning island wants to form an alliance with island .
Output Format
For each proposal, output APPROVE if it is accepted; otherwise output REFUSE.
3 1 2
1 2
2 1
1 3
REFUSE
APPROVE
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
Hint
This problem uses bundled testdata.
- Subtask 1 (15 points): , , .
- Subtask 2 (17 points): , , .
- Subtask 3 (20 points): , , .
- Subtask 4 (23 points): It is guaranteed that the number of refused proposals is at most once.
- Subtask 5 (25 points): No special constraints.
For all testdata, , , , and each pair is distinct.
Translated by ChatGPT 5