Unfriend
Time limit2sMemory limit512 MB
Count the subsets of nodes in a rooted tree that can be removed, where removing a node forces removal of all its descendants.
- Level
Easy2 of 10
- Topics
- Tree, Brute force, Combinatorics
- Solved
- No attempts yet
Problem
Mark started a social network by inviting some people. Some of the invitees invited more people, who invited still more, and so on. The network now has people, numbered from to . Person is Mark himself.
Everyone except Mark was invited by exactly one other person (nobody is invited by more than one person), so the invitations form a tree rooted at Mark.
Mark wants to remove some people from the network and keep the rest. There is one rule: whenever he removes a person, he must also remove everyone that person invited, and everyone those people invited, and so on (that is, the person's entire set of descendants is removed together with them). Mark will never remove himself, and he may also choose to remove nobody.
How many different sets of people can be removed?
Input
The first line contains a single integer (), the number of people. Each of the next lines tells who invited a person: line () contains a single integer (), meaning that person invited person . Person is Mark.
Output
Print a single integer: the number of different sets of people that can be removed.