当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3385:Genealogy

题目描述

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:

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

输入解释

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 ≤ dn). 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.

输入样例
6 2
5 5 0 5 0 5
输出样例
2

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3385

最后修改于 2020-10-29T07:00:18+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536