Movie Night
시간 제한1.5초메모리 제한1024 MB
각 친구는 특정한 다른 친구가 참석할 때만 오려고 한다. 이 의존 관계에 대해 닫힌 공집합이 아닌 부분집합의 수를 세어 10^9+7로 나눈 나머지를 구한다.
문제
You're trying to organize an outing to a movie with a group of friends. This is made complicated by the fact that your friends will decide whether to come based on who else is coming. If you give one of your friends a call, you know you're going to have a conversation like this:
- You: "Hi Fred, want to come with us to the 7:30 showing of Coding Horror from the Accidentally Quadratic Lagoon?"
- Fred: "Well, I dunno... is Francine coming?"
In fact, for each one of your friends X, there is exactly one other friend Y such that X will come only if Y also comes. Of course, you must invite a subset of your friends such that everyone invited knows who else is invited and will be willing to come, and no one uninvited will need to come.
The question is, how many such subsets of your friends are there? You don't want to go to the movies alone, so every set must have at least one friend.
입력
The first line of input contains an integer (). This is the number of friends you might invite to the movie. You identify your friends by a number from 1 to .
Each of the next lines contains a single integer (). This indicates that friend will only go to the movie if friend also goes to the movie, where is for the first value, for the second value, and so on. No one will be their own friend! (i.e., )
출력
Output a single integer, which is the number of distinct nonempty subsets of your friends you could invite such that everyone you invite will be willing to come. Since this number may be quite large, output it modulo .