题目链接:https://www.patest.cn/contests/pat-a-practise/1004
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
map<int,vector<int> >adj;
int record[101]={0};
void DFS(int id,int level){
if(adj[id].empty()){
++record[level];
return ;
}
vector<int>::iterator ite = adj[id].begin();
for(;ite!=adj[id].end();++ite){
DFS(*ite,level+1);
}
}
int main(){
int n,m;
int id,k;
cin>>n>>m;
int cle=n-m;
for(int i=0;i<m;i++){
cin>>id>>k;
for(int j=0;j<k;j++){
int a;
cin>>a;
adj[id].push_back(a);
}
}
DFS(1,0);
cout<<record[0];
int cnt=record[0];
for(int i=1;cnt<cle;i++){
cout<<" "<<record[i];
cnt+=record[i];
}
cout<<endl;
return 0;
}
网友评论