题意:

输入一个正整数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. [HNOI2003] 消防局的设立 - 树形dp

    仍然是点覆盖集问题,但覆盖半径变成了\(2\) 延续上一题的思路,只是式子更加复杂了 想体验一下min_element大法于是不想优化了 #include <bits/stdc++.h> ...

  2. JFinal Enjoy指令扩展管理常用文本模板

    个人博客 地址:http://www.wenhaofan.com/article/20190304102258 平时在项目中使用短信模板 邮件模板以及 站内消息通知等文本模板一般都是通过手动的字符串拼 ...

  3. nginx配置长连接(ajax60秒请求超时)

    个人博客 地址:http://www.wenhaofan.com/article/20180911150337 1.在使用ajax做轮训的时候前台发出的ajax请求总是会在60秒之后返回405超时响应 ...

  4. Selenium原理

      from selenium import webdriver:导入webdriver模块 当导入webdriver模块时,会执行\selenium\webdriver目录下的__init__.py ...

  5. MySQL常用命令符

    收集于网络!!!! 解决字符乱码问题:显示汉语而非乱码:set names utf8: 修改新密码:update user set password=PASSWORD('新密码') where use ...

  6. Java EE 7 API

    学习Java必备资源,下载链接: https://pan.baidu.com/s/1P1xzuoGJCIuZlYBbPSbM_Q 提取码: dtui 复制这段内容后打开百度网盘手机App,操作更方便哦

  7. 转载:android audio flinger

    https://blog.csdn.net/innost/article/details/6142812 https://blog.csdn.net/zyuanyun/article/details/ ...

  8. VNCserver 安装 及 oracle过程总结

    一.安装桌面系统 1.命令   yum grouplist ---列举系统中以组安装的包(组安装的包会包括很多,组安装一下就就可以安装很多附在的包.) 2.  yum groupinstall &qu ...

  9. Vue中自动获取input焦点

    <input v-focus type="text" name="search" ref="input" autofocus v-mo ...

  10. Mysql高级操作

    多数据插入 insert into 表名 [(字段名)] values(值列表1),(值列表2),... 主键冲突 主键冲突更新 主键冲突时,更新数据 insert into 表名 [(字段列表)] ...