#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 1001;
int n,father[maxn],isRoot[maxn];
vector<int> v[maxn];
void init()
{
for(int i = 1;i<=n;i++)
{
father[i] = i;
isRoot[i] = 0;
}
}
int findFather(int x)
{
if(father[x] == x) return x;
return findFather(father[x]);
}
void unit(int a,int b)
{
int fa,fb;
fa = findFather(a);
fb = findFather(b);
if(fa!=fb)
father[fa] = fb;
}
bool cmp(int a,int b)
{
return a > b;
}
int main()
{
freopen("1.txt","r",stdin);
scanf("%d",&n);
int course[maxn];
fill(course,course+maxn,0);
init();
for(int i = 1;i<=n;i++)
{
int k;
scanf("%d: ",&k);
for(int j = 0;j<k;j++)
{
int t;
scanf("%d",&t);
if(course[t] == 0)
{
course[t] = i;
}
unit(i,findFather(course[t]));
}
}
for(int i = 1;i<=n;i++)
{
isRoot[findFather(i)]++;
}
sort(isRoot+1,isRoot+n+1,cmp);
int num = 0;
for(int i = 1;i<=n;i++)
{
if(isRoot[i]>0)
num++;
}
printf("%d\n",num);
for(int i = 1;i<=n;i++)
{
if(isRoot[i]!=0)
{
printf("%d",isRoot[i]);
num--;
if(num>0)
printf(" ");
}
}
return 0;
}
1107 Social Clusters (30 分)(******)
猜你喜欢
转载自blog.csdn.net/qq_15556537/article/details/100833869
今日推荐
周排行