Canadian Computing Competition: 2011 Stage 1, Junior #5
Mark invited some people to join his social network. Some of them invited new people, who invited new people, and so on. Now there are people in the network, numbered from to . Mark has decided to remove some people and keep others. There is one restriction: when removing a person, he will also remove the people s/he invited, and the people they invited, and so on. Mark will never remove himself, and we do not allow people to be invited by more than one person. Mark can also decide to not remove anyone.
How many different sets of people can be removed?
The first line contains a single integer , the number of people in the network. Next are lines telling us who invited each person. To be precise, line in this set contains a single integer (with ), which indicates that person is the person who invited person . Person is Mark.
Output a single integer, the number of possible sets of people that can be removed.
Sample Input 1
3 3 3
Output for Sample Input 1
Explanation for Sample 1
The first number of the input indicates there are three people in the network. The next line tells us that Person 1 was invited by Mark, while the last line tells us that Person 2 was also invited by Mark. The sets of people that can be removed are .
Sample Input 2
4 3 4 4
Output for Sample Input 2
Explanation for Sample 2
There are 4 people in the network. Here is a table of who invited who:
The possible sets are , , , , , and . Notice that the sets and are not possible, since when you remove , you must also remove .