Thousands Islands
문제
Thousands Islands is a group of beautiful islands located in the Java Sea. It consists of islands, numbered from to .
There are canoes, numbered from to , that can be used to sail between islands. For each such that , canoe can be docked either at island or , and can be used to sail between islands and . Specifically, when the canoe is docked at island , it can be used to sail from island to island , after which the canoe becomes docked at island . Similarly, when the canoe is docked at island , it can be used to sail from island to island , after which the canoe becomes docked at island . Initially, the canoe is docked at island . It is possible that multiple canoes can be used to sail between the same pair of islands. It is also possible that multiple canoes are docked at the same island.
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 , another canoe must be used before canoe can be used again.
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 times, or determine that no such valid journey exists. It can be proven that under the constraints specified in this task (see Constraints section), if a valid journey exists, there also exists a valid journey that does not involve sailing more than times.