#include<cstdio>
#include<cstring>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cctype>
#include<vector>
#include<iomanip>
#include<queue>
#include<cassert>
#define INF 0x3f3f3f3f
using namespace std;
struct node{
int father,level;
bool leaf;
};
node t[107];
int ans[107];
int main(){
int n, m, f, c, cnt, height = 1;
bool l = 0;
for(int i = 1; i < 100; i ++) t[i].father = t[i].level = t[i].leaf = 0, ans[i] = 0;
t[1].level = 1;
cin>>n>>m;
for(int i = 0; i < m; i ++){
cin>>f>>cnt;
if(cnt > 0) t[f].leaf = 1;
for(int j = 0; j < cnt; j ++){
cin>>c;
t[c].father = f;
}
}
if(t[1].leaf == 0) ans[1] = 1;
for(int i = 1; i < 100; i ++){
for(int j = 1; j < 100; j ++){
if(t[j].father != i) continue;
t[j].level = t[i].level + 1;
if(height < t[j].level) height = t[j].level;
if(t[j].leaf == 0 && t[j].level > 0) ans[t[j].level] ++;
}
}
for(int i = 1; i <= height; i ++){
if(l) cout<<" ";
else l = 1;
cout<<ans[i];
}
}
1004. Counting Leaves (30)
最新推荐文章于 2023-10-23 19:46:08 发布