Arpa's loud Owf and Mehrdad's evil plan

题意翻译

## 题目描述 在小A的地盘上有许多可爱的妹子。 小A地盘上的所有人被从 $1$ 到 $n$ 编号,每个人都有一个暗恋的对象,第 $i$ 个人暗恋第 $crush_{i}$ 个人。 有一天,小A在宫殿的顶部大声喊着Owf,于是一个有趣的游戏在小A的地盘上开始了。规则如下。 该游戏有许多轮。如果编号为 $x$ 的人想要开始一轮游戏,他会对第 $crush_{x}$ 个人( $x$ 暗恋的人 )说"Oww...wwf"(有 $t$ 个w)。如果 $t > 1$,第 $crush_{x}$ 个人就会对第 $crush_{crush_{x}}$ 个人($crush_{x}$暗恋的人)说"Oww...wwf"(有 $t - 1$ 个w)。直到有人听到"Owf"($t = 1$)。这个人就是这一轮的Joon-Joon。不存在同时进行两轮游戏的情况。 为了使游戏更有意思,小M有一个邪恶的计划。他想找到最小的 $t$($t >= 1$)使得对于每个人 $x$ 当第 $x$ 个人开始的一局游戏使 $y$ 成为了Joon-Joon,也使得由 $y$ 开始的一局游戏 $x$ 成为Joon-Joon。请为小M找这个最小的 $t$。 可能会有自恋的人。 ## 输入输出格式 ### 输入格式: 第一行输入一个 $n$($1 <= n <= 100$)表示小A地盘上的人数。 第二行输入 $n$ 个数表示第 $i$ 个人暗恋的人 $crush_{x}$($1 <= crush_{x} <= n$)。 ### 输出格式 输出最小的 $t$,如果没有输出 $-1$。 ## 备注 题面太恶心了(~~我的翻译太菜了~~) 这道题就是输入一个链表,先让你判断链表中的点是否都在某一个环中,让后让你求出所有环的点数的lcm,对于偶数环在求lcm时将该偶数环的点数减半。

题目描述

As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered from $ 1 $ to $ n $ . Everyone has exactly one crush, $ i $ -th person's crush is person with the number $ crush_{i} $ . ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF741A/bb2e30281b644537e3f87a79c5a0ec6c97f5dc0e.png)Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as follows. The game consists of rounds. Assume person $ x $ wants to start a round, he calls $ crush_{x} $ and says: "Oww...wwf" (the letter w is repeated $ t $ times) and cuts off the phone immediately. If $ t&gt;1 $ then $ crush_{x} $ calls $ crush_{crushx} $ and says: "Oww...wwf" (the letter w is repeated $ t-1 $ times) and cuts off the phone immediately. The round continues until some person receives an "Owf" ( $ t=1 $ ). This person is called the Joon-Joon of the round. There can't be two rounds at the same time. Mehrdad has an evil plan to make the game more funny, he wants to find smallest $ t $ ( $ t>=1 $ ) such that for each person $ x $ , if $ x $ starts some round and $ y $ becomes the Joon-Joon of the round, then by starting from $ y $ , $ x $ would become the Joon-Joon of the round. Find such $ t $ for Mehrdad if it's possible. Some strange fact in Arpa's land is that someone can be himself's crush (i.e. $ crush_{i}=i $ ).

输入输出格式

输入格式


The first line of input contains integer $ n $ ( $ 1<=n<=100 $ ) — the number of people in Arpa's land. The second line contains $ n $ integers, $ i $ -th of them is $ crush_{i} $ ( $ 1<=crush_{i}<=n $ ) — the number of $ i $ -th person's crush.

输出格式


If there is no $ t $ satisfying the condition, print -1. Otherwise print such smallest $ t $ .

输入输出样例

输入样例 #1

4
2 3 1 4

输出样例 #1

3

输入样例 #2

4
4 4 4 4

输出样例 #2

-1

输入样例 #3

4
2 1 4 3

输出样例 #3

1

说明

In the first sample suppose $ t=3 $ . If the first person starts some round: The first person calls the second person and says "Owwwf", then the second person calls the third person and says "Owwf", then the third person calls the first person and says "Owf", so the first person becomes Joon-Joon of the round. So the condition is satisfied if $ x $ is $ 1 $ . The process is similar for the second and the third person. If the fourth person starts some round: The fourth person calls himself and says "Owwwf", then he calls himself again and says "Owwf", then he calls himself for another time and says "Owf", so the fourth person becomes Joon-Joon of the round. So the condition is satisfied when $ x $ is $ 4 $ . In the last example if the first person starts a round, then the second person becomes the Joon-Joon, and vice versa.