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



?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,872評論 0 10
  • 晴,殘云游弋,炙陽噴薄。 洛陽,港巷千萬,人潮鴻涌。一條騰江,如銀龍盤附,徐徐繞繞,穿城而過。 城中酒肆,人聲滔滔...
    橡木船閱讀 343評論 1 0
  • 媽媽日記片段:下午小寶睡覺時間,我看了一篇報到,十一假期在外工作的游子回家探望,有一個兩歲的小孩在自己的爸爸媽媽臨...
    武際金閱讀 1,781評論 0 8
  • 如果你真心渴望做成一件事情,整個宇宙都會聯(lián)合起來幫助你。
    行走的店小二閱讀 189評論 0 0

友情鏈接更多精彩內(nèi)容