题目 https://www.patest.cn/contests/gplt/L3-3
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>a[1002];
int vis[1002],visit[1002];
int num=1,n;
queue<int> q;
vector<int >ans;
int find_r(int hh,int temp)
{
for(int i=1;i<=n;i++){
for(int j=0;j<a[i].size();j++){
if(a[i][j]==hh&&i!=temp){
num++;
q.push(i);
visit[i]=1;
}
}
}
}
void bfs(int pp)
{
q.push(pp);
while(!q.empty()){
int temp=q.front();
q.pop();
for(int i=0;i<a[temp].size();i++){
int hh=a[temp][i];
if(vis[hh]==0){
find_r(hh,temp);
vis[hh]=1;
}
}
}
}
int com(int a,int b)
{
return a>b;
}
int main()
{
int k,t;
cin>>n;
memset(vis,0,sizeof(vis));
memset(visit,0,sizeof(visit));
for(int i=1;i<=n;i++){
cin>>k;
getchar();
while(k--){
cin>>t;
a[i].push_back(t);
}
}
for(int i=1;i<=n;i++){
if(visit[i]==0){
bfs(i);
ans.push_back(num);
num=1;
}
}
sort(ans.begin(),ans.end(),com);
printf("%d\n",ans.size());
printf("%d",ans[0]);
for(int i=1;i<ans.size();i++){
printf(" %d",ans[i]);
}
return 0;
}