Thousands Islands is a group of beautiful islands located in the Java Sea.
It consists of
There are
For safety reasons, a canoe needs to be maintained after every time it is sailed, which forbids the same canoe to be sailed two times in a row.
That is, after using some canoe
Bu Dengklek wants to plan a journey through some of the islands. Her journey is valid if and only if the following conditions are satisfied.
- She starts and ends her journey at island
. - She visits at least one island other than island
. - After the journey ends, each canoe is docked at the same island as it was before the journey.
I.e., canoe
, for each such that , must be docked at island .
Help Bu Dengklek find any valid journey involving sailing at most
Implementation Details
You should implement the following procedure:
std::variant<bool, std::vector<int>> find_journey(int N, int M, std::vector<int> U, std::vector<int> V)
: the number of islands. : the number of canoes. , : arrays of length describing the canoes.- This procedure should return either a boolean or an array of integers.
- If no valid journey exists, the procedure should return
false
. - If a valid journey exists, you have two options:
- To be awarded the full score, the procedure should return an array of at most
integers representing a valid journey. More precisely, the elements of this array should be the numbers of the canoes that are used in the journey (in the order they are used). - To be awarded a partial score, the procedure should return
true
, an array of more than integers, or an array of integers not describing a valid journey. (See the Subtasks section for more details.)
- To be awarded the full score, the procedure should return an array of at most
- If no valid journey exists, the procedure should return
- This procedure is called exactly once.
Examples
Example 1
Consider the following call:
find_journey(4, 5, {0, 1, 2, 0, 3}, {1, 2, 3, 3, 1})
The islands and canoes are shown in the picture below.

One possible valid journey is as follows.
Bu Dengklek first sails canoes
Therefore, the returned value
Example 2
Consider the following call:
find_journey(2, 3, {0, 1, 1}, {1, 0, 0})
The islands and canoes are shown in the picture below.

Bu Dengklek can only start by sailing canoe false
.
Constraints
and (for each such that ) (for each such that )
Subtasks
- (5 points)
- (5 points)
. For each pair of distinct islands and , there are exactly two canoes that can be used to sail between them. One of them is docked at island , and the other one is docked at island . - (21 points)
, is even, and for each even such that , canoes and can both be used to sail between islands and . Canoe is initially docked at island and canoe is initially docked at island . Formally, and . - (24 points)
, is even, and for each even such that , canoes and can both be used to sail between islands and . Both canoes are initially docked at island . Formally, and . - (45 points) No additional constraints.
For each test case in which a valid journey exists, your solution:
- gets full points if it returns a valid journey,
- gets
of the points if it returnstrue
, an array of more than integers, or an array that does not describe a valid journey, - gets
points otherwise.
For each test case in which a valid journey does not exist, your solution:
- gets full points if it returns
false
, - gets
points otherwise.
Note that the final score for each subtask is the minimum of the points for the test cases in the subtask.
Sample Grader
The sample grader reads the input in the following format:
- line
: - line
:
The sample grader prints your answers in the following format:
- If
find_journey
returns abool
:- line
: - line
: iffind_journey
returnsfalse
, or otherwise.
- line
- If
find_journey
returns astd::vector<int>
, denote the elements of this array by . The sample grader prints:- line
: - line
: - line
:
- line
Attachment Package
The sample grader along with sample test cases are available here.
Comments