#include<iostream>
#include<cstring>
using namespace std;
int child_flag[100][100];
int num_node;
int num_noleaf;
int num_leaf[100];
bool num_leaf_flag[100];
int i,j;
//int tree_high;
void level_count(int node,int level)
{
num_leaf_flag[level] = true;
int flag = true;
for(int k = 1;k <= num_node;++k)
{
if(child_flag[node][k])
{
flag = false;
level_count(k,level + 1);
}
}
//tree_high++;
if(flag)
{
num_leaf[level]++;
}
}
int main()
{
int k,node,node1;
//tree_high = 0;
memset(child_flag,0,sizeof(child_flag));
memset(num_leaf,0,sizeof(num_leaf));
memset(num_leaf_flag,0,sizeof(num_leaf_flag));
cin>>num_node>>num_noleaf;
for(i = 0;i < num_noleaf;i++)
{
cin>>node>>k;
for(j = 0;j < k;j++)
{
cin>>node1;
child_flag[node][node1] = 1;
}
}
level_count(1,1);
for(i = 1;num_leaf_flag[i];i++) ;
for(j = 1;j < i - 1;j++)cout<<num_leaf[j]<<" ";
cout<<num_leaf[i - 1]<<endl;
return 0;
}
题目链接: http://pat.zju.edu.cn/contests/pat-a-practise/1004