代码:
#include<iostream>
#include<vector>
#include<map>
using namespace std;
int m, n;
int level, maxn=-1;
map<int, int>sk;
vector<vector<int> >pp;
void dfs(int index, int high)
{
if (maxn < high)maxn = high;
if (pp[index].size() != 0)
{
for (int i = 0; i < pp[index].size(); i++)
dfs(pp[index][i], high + 1);
}
else
{
sk[high]++;
}
}
int main()
{
cin >> n >> m;
pp.resize(n + 1);
for (int i = 0; i < 1000; i++)
sk[i] = 0;
for (int i = 1; i <= m; i++)
{
int a, b;
cin >> a >> b;
for (int j = 0; j < b; j++)
{
int c;
cin >> c;
pp[a].push_back(c);
}
}
dfs(1, 0);
for (int i = 0; i <= maxn;i++)
{
cout <<sk[i];
if (i!=maxn)cout << " ";
}
return 0;
}