题意:

输入一个正整数N(<=1000),表示人数,接着输入N行每行包括一个他的爱好数量:和爱好的序号。拥有相同爱好的人们可以默认他们在同一个俱乐部,输出俱乐部的数量并从大到小输出俱乐部的人数(不同俱乐部的两个人的爱好一定不相同)。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
vector<int>v[],st;
int fa[];
int a[];
int find_(int x){
int k,j,r;
r=x;
while(r!=fa[r])
r=fa[r];
k=x;
while(k!=r){
j=fa[k];
fa[k]=r;
k=j;
}
return r;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
st.resize(n+);
for(int i=;i<=n;++i)
fa[i]=i;
for(int i=;i<=n;++i){
int x;
cin>>x;
cin.ignore();
for(int j=;j<=x;++j){
int y;
cin>>y;
v[i].push_back(y);
}
}
for(int i=;i<=n;++i)
for(auto it:v[i])
if(!a[it])
a[it]=i;
else{
int x=find_(i);
int y=find_(a[it]);
if(x!=y)
fa[x]=y;
}
for(int i=;i<=n;++i)
++st[find_(i)];
int cnt=;
for(int i=;i<=n;++i)
if(st[i])
++cnt;
cout<<cnt<<"\n";
sort(st.rbegin(),st.rend());
for(int i=;i<cnt;++i){
cout<<st[i];
if(i<cnt-)
cout<<" ";
}
return ;
}

【PAT甲级】1107 Social Clusters (30分)(非递归并查集)的更多相关文章

  1. pat甲级 1107. Social Clusters (30)

    When register on a social network, you are always asked to specify your hobbies in order to find som ...

  2. PAT甲级1107. Social Clusters

    PAT甲级1107. Social Clusters 题意: 当在社交网络上注册时,您总是被要求指定您的爱好,以便找到一些具有相同兴趣的潜在朋友.一个"社会群体"是一群拥有一些共同 ...

  3. PAT甲级——1107 Social Clusters (并查集)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90409731 1107 Social Clusters (30  ...

  4. PAT-1107 Social Clusters (30 分) 并查集模板

    1107 Social Clusters (30 分) When register on a social network, you are always asked to specify your ...

  5. [并查集] 1107. Social Clusters (30)

    1107. Social Clusters (30) When register on a social network, you are always asked to specify your h ...

  6. 非递归并查集——zoj4109

    卡常卡的我难受 非递归并查集好像写起来常数小一点 int F[maxn]; int Find(int x){ int r = x; while (F[r] != r)r = F[r]; int i = ...

  7. 1107 Social Clusters (30)(30 分)

    When register on a social network, you are always asked to specify your hobbies in order to find som ...

  8. PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)

    1080 Graduate Admission (30 分)   It is said that in 2011, there are about 100 graduate schools ready ...

  9. PAT 甲级 1072 Gas Station (30 分)(dijstra)

    1072 Gas Station (30 分)   A gas station has to be built at such a location that the minimum distance ...

随机推荐

  1. Vuex项目实战store

    首先简单了解一下什么是Vuex? Vuex是一个专为Vue.js应用程序开发的状态管理模式.采用集中式存储来管理应用所有组件的状态. 以下是对vuex的使用的简单介绍: 一.安装 npm i vuex ...

  2. [USACO10MAR] 伟大的奶牛聚集 - 树形dp

    每个点有重数,求到所有点距离最小的点 就是魔改的重心了 #include <bits/stdc++.h> using namespace std; #define int long lon ...

  3. WSO2 ESB XML定义语法(3)

    6.Property Mediator 通过Synapse调解的每条消息都可以具有一组关联的属性.Synapse引擎和底层传输在处理的每条消息上设置了许多属性,用户可以操纵这些属性来修改消息流的运行时 ...

  4. Facebook Create Done!

    前天,又一次开了VPN,建立了自己的Facebook! Facebook我用邮箱注册的,注册邮箱在这里: acmit1966@outlook.com Facebook上我就叫做 Jack Deng 在 ...

  5. HTML文本域标签

    textarea文本域 cols指定列数 rows行数(不够用会自动扩容)

  6. NotePad++中如何改变光标样式(转换横着和竖着)?

    在键盘上找 Insert ,按这个Insert就可以把横向闪烁光标( _ )修改成竖向闪烁光标样式( | )

  7. ping和tracert

    ping命令常用于测试2台主机网络是否连通 TTL的默认值有:64(linux),128(windows),255(路由器) 此例TTL是63所以选用64来减去63等于1,这是说明经过了1个路由器,没 ...

  8. video.js 后端网页播放器

    参考链接: https://www.cnblogs.com/afrog/p/6689179.html VideoJS的CSS样式,这里我提供一下BootCdn的链接 cdn.bootcss.com/v ...

  9. LED Decorative Light Supplier - LED Neon Application: 5 Advantages

    In the past 100 years, lighting has gone a long way. LED decorative lighting is now designed to meet ...

  10. CSS布局的四种定位方式

    1.static(静态定位): 默认值.没有定位,元素出现在正常的流中(忽略 top, bottom, left, right 或者 z-index 声明).参考上篇随笔. 2.relative(相对 ...