A1107
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1001;
int n,course[maxn]={0},father[maxn],isRoot[maxn]={0};
bool cmp(int a, int b)
{
return a>b;
}
void init()
{
for(int i=1; i<=n; i++)
{
father[i]=i;
}
}
int findFather(int x)
{
while(x!=father[x])
x=father[x];
return x;
}
void Union(int a, int b)
{
int faA=findFather(a);
int faB=findFather(b);
if(faA!=faB)
father[faA]=faB;
}
int main()
{
cin >> n;
init();
int temp,temp1;
for(int i=1; i<=n; i++)
{
scanf("%d:",&temp);
for(int j=0; j<temp; j++)
{
cin >> temp1;
if(course[temp1]==0)
{
course[temp1]=i;
}
Union(i,course[temp1]);
}
}
for(int i=1; i<=n; i++)
{
isRoot[findFather(i)]++;
}
int ans=0;
for(int i=1; i<=n; i++)
{
if(isRoot[i]!=0)
ans++;
}
sort(isRoot+1,isRoot+n,cmp);
cout << ans << endl;
for(int i=1; i<=ans; i++)
{
if(i!=1)
cout << " ";
cout << isRoot[i];
}
return 0;
}
转载请注明原文地址:https://blackberry.8miu.com/read-8296.html