//题意:找当前层共有几个叶子结点。
/*
数据:
4 2
01 2 02 03
03 1 04
0 1 1
2 1
01 1 02
0 1
*/
#include"stdafx.h"
#include<iostream>
#include<string>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct tree {
int father = 0;
int nochild = 0;
int level = 1;
}t[150];
int n, m, i, j, total[150], maxlevel = 1;
int main()
{
//节点个数 非叶节点个数。
//他可以先输入子节点,然后输入根结点,在这种情况下,需要重新排列层数。
int id, count, child;
cin >> n >> m;
for (i = 0; i < m; ++i)
{
cin >> id >> count;
if (count)
t[id].nochild = 1;
for (j = 0; j < count; ++j)
{
cin >> child;
t[child].father = id;
//t[child].level = t[id].level + 1;//没有考虑乱序,导致1,3节点不能过
//maxlevel = max(maxlevel, t[child].level);//没有考虑乱序,导致1,3节点不能过
}
}
for (i = 1; i <= n; ++i)//这里是针对乱序的数据进行修改的代码。
{
int now = i, levelnow = 1;
while (t[now].father != 0)
{
now = t[now].father;
++levelnow;
}
t[i].level = levelnow;
maxlevel = max(maxlevel, levelnow);
}
//如果自己没有儿子,那么total当前层数的叶子节点数目++;
for (i = 1; i <= n; ++i) {
if (t[i].nochild != 1)
++total[t[i].level];
}
for (i = 1; i < maxlevel; ++i)
cout << total[i] << " ";
cout << total[i];
return 0;
}