#include<stdio.h>
//问每一层多少叶子结点
struct TreeNode{
int id=0;//结点编号
int childCount=0;//孩子数量,为零即叶子
int children[100]={0};//孩子结点编号数组
};
struct TreeNode tree[100];
int main(){
int n,m;
scanf("%d",&n);
if(n!=0){
for(int i=0;i<100;i++){
tree[i].id=i;
}
scanf("%d",&m);
for(int i=0;i<m;i++){
int id,childCount;
scanf("%d %d",&id,&childCount);
tree[id].id=id;
tree[id].childCount=childCount;
for(int j=0;j<childCount;j++){
int children;
scanf("%d",&children);
tree[id].children[j]=children;
}
}
//每一层多少个叶子结点,难道不应该层序遍历吗?
//我需要一个队列
TreeNode quene[100];
int front=0,rear=0;
TreeNode root=tree[1];
quene[rear]=root;//后面进,前面出
rear++;
while(front<rear){
for(int i=0;i<quene[front].childCount;i++){
quene[rear]=tree[quene[front].children[i]];//其实就是插入num=quene[front].children[i]的树
rear++;
}
front++;
}
int p=0;//从根节点开始遍历
int leafCount=0;//叶子数量
//我需要记录这一层的最后一个结点,还要记录这一层最后一个有孩子的结点!,应该是上一层最后一个(有孩子的)结点的最后一个孩子就是这一层最后一个结点!
TreeNode thisLast,lastLast;
int lastParent=0;//上一层最后一对父母
thisLast=root;//这一层最后就是root
while(p!=n){//n是总结点数
if(p!=0)
printf(" ");
leafCount=0;
while(quene[p].id!=thisLast.id){
if(quene[p].childCount==0){
leafCount++;
}else{
lastParent=p;
}
p++;
}
if(quene[p].childCount==0){//此时quene[p]==thisLast
leafCount++;
}else{
lastParent=p;
}
p++;
printf("%d",leafCount);
lastLast=quene[lastParent];
thisLast=tree[lastLast.children[lastLast.childCount-1]];
}
}
return 0;
}