406819: GYM102565 H Shopping Bags

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

H. Shopping Bagstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Since Jimmy and Johnny are not allowed to leave their home, they have created a game out of boredom, but because they didn't have many things to play with in the house, they have used shopping bags. An interesting property of shopping bags is that they can fit inside other bags which can fit inside others and so on. So the 2 kids have used N bags, indexed from 1 to N, deciding for each one whether to put it in another bag or not.

After finishing the slow process of putting bags inside each other, the kids can start playing. They take turns, Jimmy being the first one to make a move. In a move, a kid can choose a bag that is still in the game and remove it together with all the bags inside it out of the game. The loser is the player that has no more bags to choose from when it is his turn.

Jimmy is a very competitive player, so he needs your help to tell him if, for a certain configuration of bags, he has a safe winning strategy or not.

Input

The first line of the input will contain one positive integer $$$N$$$ ($$$1 \leq N \leq 1000$$$) that represents the number of shopping bags.

The next line will contain $$$N$$$ integers $$$b_1,b_2,b_3,...,b_n$$$, where $$$b_i$$$ ($$$0 \leq b_i \leq N$$$) represents the bag that the $$$i^{th}$$$ bag is directly inside in. If $$$b_i$$$ is equal to $$$0$$$ that means that the $$$i^{th}$$$ bag isn't inside any other bag.

Output

The output should be either $$$YES$$$ if Jimmy has a safe winning strategy or $$$NO$$$ if he doesn't.

ExamplesInput
5
0 1 2 3 4
Output
YES
Input
6
0 1 2 2 0 5
Output
NO
Input
5
0 1 1 0 4
Output
YES
Note

In the first example Jimmy can choose to take out bag number $$$1$$$ as his first move, making Johnny lose.

In the second example, if Johnny plays optimal, Jimmy will lose no matter what his strategy is.

In the third example, Jimmy has a safe winning strategy.

加入题单

算法标签: