编程介的小学生 2017-05-13 16:36 采纳率: 20.5%
浏览 708
已采纳

Genealogy

Description

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:

Input

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.

Output

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

Sample Input

6 2
5 5 0 5 0 5
Sample Output

2

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-05-31 02:59
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊