PivotOJ

Thousands Islands

시간 제한: 1000ms메모리 제한: 1024MB출처: IOI 2022BOJ 25443

문제

Thousands Islands is a group of beautiful islands located in the Java Sea. It consists of NN islands, numbered from 00 to N1N - 1.

There are MM canoes, numbered from 00 to M1M - 1, that can be used to sail between islands. For each ii such that 0iM10 \le i \le M - 1, canoe ii can be docked either at island U[i]U[i] or V[i]V[i], and can be used to sail between islands U[i]U[i] and V[i]V[i]. Specifically, when the canoe is docked at island U[i]U[i], it can be used to sail from island U[i]U[i] to island V[i]V[i], after which the canoe becomes docked at island V[i]V[i]. Similarly, when the canoe is docked at island V[i]V[i], it can be used to sail from island V[i]V[i] to island U[i]U[i], after which the canoe becomes docked at island U[i]U[i]. Initially, the canoe is docked at island U[i]U[i]. 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 ii, another canoe must be used before canoe ii 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 00.
  • She visits at least one island other than island 00.
  • After the journey ends, each canoe is docked at the same island as it was before the journey. I.e., canoe ii, for each ii such that 0iM10 \le i \le M - 1, must be docked at island U[i]U[i].

Help Bu Dengklek find any valid journey involving sailing at most 20000002\,000\,000 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 20000002\,000\,000 times.

코드를 제출하려면 로그인하세요.