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

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

MAFIJA

시간 제한1초메모리 제한256 MB

요약
N명이 한 명씩 지목한 결과가 주어질 때 조직원이 조직원을 지목하지 않는다는 조건에서 가능한 조직원 수의 최댓값을 구합니다.
난이도

보통10점 중 6점

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

문제

Mafia is a social game played frequently by high school competitors in informatics on summer and winter camps and national competitions, usually very late at night, drinking various fruit sodas. This game is not about winning, it's about los taking part, like in competitions.

To solve this task, you don't need to know the rules of mafia; all you need to know is that some of the players are "mobsters" and the rest are "civilians". The mobsters know who is who, but the civilians don't. The civilians are trying to figure out who the mobsters are during the game.

In the current round of the game, out of N surviving players so far, each one has accused exactly one other player saying that he is the mobster. The civilians were only guessing and the mobsters have accused civilians, pretending to know nothing.

Not knowing who the mobsters are, but knowing who accused whom, determine the maximum possible number of mobsters among these players!

입력

The first line of input contains the integer N (2 < N < 500 000), the number of players. The players are labeled with integers from 1 to N.

The Kth line of input, out of the following N lines, contains the label of the player accused by the player K. (No player can accuse themselves.)

출력

The first and only line of output must contain the maximum possible number of mobsters.

힌트

Clarification of the first sample test: The mobster can be player 2 and 3.

Clarification of the second sample test: The mobster can be any player, but there cannot be more of them because that would mean that one of them accused the other.

예제4

  1. 예제 1

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

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

    입력
    7
    3
    3
    4
    5
    6
    4
    4
    
    예상 출력
    2
    
  4. 예제 4

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