아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Movie Night

시간 제한1.5초메모리 제한1024 MB

요약
각 친구는 특정한 다른 친구가 참석할 때만 오려고 한다. 이 의존 관계에 대해 닫힌 공집합이 아닌 부분집합의 수를 세어 10^9+7로 나눈 나머지를 구한다.
난이도

보통10점 중 6점

유형
그래프, DFS, 동적 계획법, 조합론
정답자
아직 제출이 없습니다

문제

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 nn (2≤n≤1052 \le n \le 10^5). This is the number of friends you might invite to the movie. You identify your friends by a number from 1 to nn.

Each of the next nn lines contains a single integer yy (1≤y≤n1 \le y \le n). This indicates that friend xx will only go to the movie if friend yy also goes to the movie, where xx is 11 for the first yy value, 22 for the second yy value, and so on. No one will be their own friend! (i.e., x≠yx \ne y)

출력

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 109+710^9 + 7.

예제2

  1. 예제 1

    입력
    4
    2
    3
    4
    3
    
    예상 출력
    3
    
  2. 예제 2

    입력
    5
    2
    3
    1
    5
    4
    
    예상 출력
    3