Unfriend | 프로그래밍의 벗 PivotOJ
PivotOJ

Unfriend

시간 제한: 2000ms메모리 제한: 512MB출처: CCC 2011 JuniorBOJ 6782

문제

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 N people in the network, numbered from 1 to N. 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 N (N ≤ 6), the number of people in the network. Next are N − 1 lines telling us who invited each person. To be precise, line i in this set (1 ≤ i ≤ N − 1) contains a single integer j (with j > i), which indicates that person j is the person who invited person i. Person N is Mark.

출력

Output a single integer, the number of possible sets of people that can be removed.

예제

예제 1

입력
3
3
3
출력
4

예제 2

입력
4
3
4
4
출력
6
코드를 제출하려면 로그인하세요.