编程介的小学生 2018-12-15 07:43 采纳率: 20.5%
浏览 399
已采纳

另一个二叉树方面的问题,用C语言计算最大节点的值?

Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation. He's given Rikka many math tasks to practice but she hasn't solved any of them. So, today he comes up with a simple problem to help her build up confidence:

Here is a tree with m nodes, you can delete some of the nodes on the tree and there mustn't be any edges connecting two remained nodes. You need to maximize the number of the points remained.

Rikka thinks this task is too simple, so she comes up with a new problem:

At first there is a tree with only one node. And then each time she links a new node to the tree. After each operation, you need to tell her the maximum number of the points remained (as described above).

This problem is too difficult for Rikka to solve. Can you help her?

Input
There are no more than 100 testcases and there are no more than 3 testcases with n>103.

For each testcase, the first line contains a number n (1≤n≤105).

Then n−1 lines follow. The ith line contains a single number fi (0≤fi<i), which means that after the ith operation there is a new node numbered i and there is an edge between node i and node fi.

Output
For each operation you need to print a single line with a single number - the answer after this operation.

Sample Input
4
0
0
1

Sample Output
1
2
2

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-08-08 23:04
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序