题意:

输入一个正整数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. Windows中配置MySQL环境变量

    安装好MySQL后,在Windows环境下配置环境变量 1)新建MYSQL_HOME系统变量 配置MySQL的安装路径:C:\Program Files\MySQL\MySQL Server 5.7 ...

  2. npm 升级到最新版本

    先npm -v查看自己的npm 是否是最新版本,如果不是则进入安装node的文件夹,可通过 where node 查找该文件夹. 进入之后使用: npm i npm -g 之后使用: npm -v 查 ...

  3. Oracle VM VirtualBox - VBOX_E_FILE_ERROR (0x80BB0004)

    问题描述: 导入虚拟电脑 D:\LR\虚拟机相关\CentOS-6.7-x86_64-2G-40G-oracle-IP9\CentOS-6.7-x86_64-2G-40G-oracle-IP9.ovf ...

  4. IDEA构建maven项目生成的文件详解

    IDEA构建的maven+springBoot项目结构如下: 1. .gitignore:分布式版本控制系统git的配置文件,意思为忽略提交 在 .gitingore 文件中,遵循相应的语法,即在每一 ...

  5. VSCode C语言编程(一)环境搭建

    1.安装Visual Studio Code 2. 安装MinGW编译器 有两种方法 方法(1) 打开https://sourceforge.net/projects/mingw-w64/files/ ...

  6. HTML-表格-基础表格

      主要内容: HTML表格 基本语法和结构: 案例: border用在table标签里面,表示边框的. th标签是加粗,width是宽度,表格宽度用在table里面.: caption用在table ...

  7. QQ第三方登录(一)

    要实现QQ第三方登陆 这就需要QQ方面的支持. 首先  我们需要在QQ开发者网站上注册,https://connect.qq.com/index.html 登陆之后点击应用管理,正常情况下我们是未提交 ...

  8. 1.spring源码-BeanPostProcessor后置处理器

    1.BeanPostProcessor接口的介绍: BeanPostProcessor是一个接口,其中有两个方法,postProcessBeforeInitialization和postProcess ...

  9. c数据结构 -- 链表的理解

    链表是结构体变量与结构体变量链接在一起,怎么链接在一起?通过指针 #include <stdio.h> struct Node{ int data; struct Node* next; ...

  10. Python_包

    包 包是一种通过使用‘.模块名’来组织python模块名称空间的方式. 1. 无论是import形式还是from...import形式,凡是在导入语句中(而不是在使用时)遇到带点的,都要第一时间提高警 ...