Problem Description
Moana is the story of a Polynesian girl of the same name who, together with the demigod Maui, defy impossible odds to save her people.
Having done so, she now leads her people to discover new islands in the Pacific to settle, in line with their historical tradition of voyaging. During the expeditions, she discovers
Having settled all islands, Moana now wants to set up a network of safe sailing routes that connects all the islands to promote trade, visiting, and cultural exchanges. To be safe, the routes must not be under any threat from pirates. Since the Polynesians have perfected the art of wayfinding, being able to read the stars, the sun, and the ocean's swells to navigate, sailing routes can extend infinitely, traversing the deepest oceans and crossing the stormiest seas.
A sailing route consists of an unbroken chain of ocean tiles connected in any of the four cardinal directions. It begins from any point on one island and ends on any point of another. A patrol sailboat will then be dispatched to guard each tile of the routes to protect the vital sea lanes. Intersections between sailing routes will have additional patrol sailboats deployed, equal to the number of routes involved in the intersection, as it is a more likely area of attack. Since resources are limited, help Moana find out what is the minimum number of patrol sailboats that must be built for this purpose!
Input
The first line contains five integers,
The next
Subsequent
Output
The output should only consist of one integer, the minimum number of patrol sailboats that must be built to connect all islands. If it is impossible to connect all islands, output
Constraints
For all subtasks:
Subtask 1 [15%]
Islands are distributed in a checkerboard pattern, with the first grid always being occupied.
Subtask 2 [45%]
Subtask 3 [20%]
Subtask 4 [20%]
No additional constraints.
Sample Input
4 0 0 4 5
1 2
2 3
3 4
4 1
Sample Output
5
Explanation for Sample Output
The image above shows a
Comments
This question is sort of confusing. It says:
Can this be elaborated on?