Genealogy | 프로그래밍의 벗 PivotOJ
PivotOJ

Genealogy

시간 제한: 2000ms메모리 제한: 64MB출처: NEERC Northern Subregional 2006BOJ 3621
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

Alien Peter wants to trace his family pedigrees. Working hard for several weeks, he has created a beta version of his family tree. Unfortunately, some of his ancestors have too much parents in this tree (aliens have d parents). So Peter thinks that some of parent-child relations actually are ancestor-descendant relations. Now Peter wants to know, what minimal number of ancestors need to be added to the tree to make it look well-formed (family tree looks well-formed if each alien has no more than d parents, each alien must appear at the tree only once).

For example, if d = 2, and beta-version of the family tree looks like this:

[이미지 1]

then Peter should add at least two ancestors to make it look well-formed:

[이미지 2]

입력

Let Peter’s ancestors, appeared in the beta-version of his family tree, have identifiers from 1 to n (let Peter’s identifier be 0).

The first line of input file contains numbers n and d (2 ≤ n ≤ 100 000, 2 ≤ d ≤ n). The following line contains n numbers, the i-th number is an identifier of the child of the i-th alien.

출력

Write the minimal number of Peter’s ancestors, that should be added to this tree to make it look well formed.

예제

예제 1

입력
6 2
5 5 0 5 0 5
출력
2
코드를 제출하려면 로그인하세요.