1004 Counting Leaves

1004 Counting Leaves (30)(30 分)

A family hierarchy is usually presented by a pedigree tree. Your job is

to count those family members who have no child.

Input

Each input file contains one test case. Each case starts with a line

containing 0 < N < 100, the number of nodes in a tree, and M (<

N), the number of non-leaf nodes. Then M lines follow, each in the

format:

ID K ID[1] ID[2] ... ID[K]

where ID is a two-digit number representing a given non-leaf node, K is

the number of its children, followed by a sequence of two-digit ID's of

its children. For the sake of simplicity, let us fix the root ID to be

01.

Output

For each test case, you are supposed to count those family members whohave no childfor every seniority levelstarting from the root. Thenumbers must be printed in a line, separated by a space, and there mustbe no extra space at the end of each line.

The sample case represents a tree with only 2 nodes, where 01 is the

root and 02 is its only child. Hence on the root 01 level, there is 0

leaf node; and on the next level, there is 1 leaf node. Then we should

output "0 1" in a line.

Sample Input

2 1

01 1 02

Sample Output

0 1



©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,419评论 0 10
  • 晴,残云游弋,炙阳喷薄。 洛阳,港巷千万,人潮鸿涌。一条腾江,如银龙盘附,徐徐绕绕,穿城而过。 城中酒肆,人声滔滔...
    橡木船阅读 315评论 1 0
  • 妈妈日记片段:下午小宝睡觉时间,我看了一篇报到,十一假期在外工作的游子回家探望,有一个两岁的小孩在自己的爸爸妈妈临...
    武际金阅读 1,726评论 0 8
  • 如果你真心渴望做成一件事情,整个宇宙都会联合起来帮助你。
    行走的店小二阅读 142评论 0 0