4016 {
4017 int n;
4018 int m;
4019 cin >> n >> m;
4020 if(n == 0) {
4021 return 0;
4022 }
4023 unordered_map<string, node *> um;
4024 for(int i = 0; i < m; i++) {
4025 string id;
4026 int k;
4027 cin >> id >> k;
4028 if(!um.contains(id)) {
4029 um[id] = new node(id);
4030 }
4031 auto *const nd = um[id];
4032 for(int j = 0; j < k; j++) {
4033 string cid;
4034 cin >> cid;
4035 if(!um.contains(cid)) {
4036 um[cid] = new node(cid);
4037 }
4038 nd->children.insert(um[cid]);
4039 }
4040 }
4041 queue<pair<node *, int>> q;
4042 q.push(make_pair(um["01"], 0));
4043 if(um["01"] == nullptr) {
4044 cout << 1;
4045 return 0;
4046 }
4047 int current_level = 0;
4048 int leaf_cnt = 0;
4049 while(!q.empty()) {
4050 auto [nd, level] = q.front();
4051 q.pop();
4052 if(level != current_level) {
4053 if(current_level != 0) {
4054 cout << ' ';
4055 }
4056 current_level = level;
4057 cout << leaf_cnt;
4058 leaf_cnt = 0;
4059 }
4060 if(nd->children.empty()) {
4061 leaf_cnt++;
4062 }
4063 for(auto *c: nd->children) {
4064 q.push(make_pair(c, level + 1));
4065 }
4066 }
4067 cout << ' ' << leaf_cnt;
4068 return 0;
4069 }