#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
const int maxn=100010;
struct Node
{
int weight;
vector<int> child;
}node[maxn];
int n;
int p;
int ans=0;
int _time[maxn]={0};
int maxdepth=0;
void dfs(int index,int depth)
{
if(node[index].child.size()==0)
{
_time[depth]++;
if(depth>maxdepth)
{
maxdepth=depth;
}
return;
}
for(int i=0;i<node[index].child.size();i++)
{
int child=node[index].child[i];
dfs(child,depth+1);
}
}
int main()
{
scanf("%d%d",&n,&p);
int id,k,child;
for(int i=0;i<p;i++)
{
scanf("%d%d",&id,&k);
for(int j=0;j<k;j++)
{
scanf("%d",&child);
node[id].child.push_back(child);
}
}
dfs(1,1);
for(int i=1;i<maxdepth;i++)
{
printf("%d ",_time[i]);
}
printf("%d",_time[maxdepth]);
system("pause");
return 0;
}
PAT 1004
最新推荐文章于 2022-07-26 16:28:25 发布