题意:

输入一个正整数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. MariaDB Windows 安装

    1.复制安装文件到服务器 2.解压到指定的目录,并创建my.ini: 3.编辑my.ini文件内容 [client] port=3307 [mysql] default-character-set=u ...

  2. 对Ajax返回的json数据做处理报错

    这个错误出现的原因是我再返回数据为json时,我页面的Ajax没有指定dataType: 'json'

  3. IntelliJ IDEA 2019.1.3 最新破解教程【最强 可用至2099年】

    本文包括最新[2019.1.2]安装 和[2018.3.2](推荐)安装 ①IntelliJ IDEA 2018.3.2安装永久安装[最强]  一. 在官网下载IDEA安装包  链接:https:// ...

  4. linux安装php-laravel环境

    1.运用传说中的宝塔面板安装(https://www.bt.cn/download/linux.html)网站地址 在xshell软件中安装一下命令 1.1 宝塔centos安装 wget -O in ...

  5. 一、c++语言基础

    1. 程序员的第一条代码"Hello,world!" #include <cstdio> //头文件,主要负责输入.输出 using namespace std;//C ...

  6. Django中content-type组件的使用

    content-type组件 ContentType是Django的内置的一个应用,可以追踪项目的所有APP和model的对应关系,并记录在ContentTpe表中,当我们的项目做数据迁移后,会有很多 ...

  7. 题解【洛谷P5959】[POI2018]Plan metra

    题面 一道比较神仙的构造题. 首先确定 \(1\) 到 \(n\) 的路径长度,不妨设其长为 \(m\) . 通过观察发现,\(m\) 就是 \(\min_{1<i<n}\{dist_{1 ...

  8. EF中的查询方法

    1.Linq to Entity(L2E)查询 默认返回IQueryable类型 2.原生SQL查询和操作 ①DbSet.SqlQuery()和Database.SqlQuery() 返回DbSqlQ ...

  9. 使用NSIS制作可执行程序的安装包

    使用NSIS制作可执行程序的安装包: 1,NSIS下载地址:https://pan.baidu.com/s/1GzzQNXgAlJPJWgjBzVwceA 下载完成之后解压缩,打开安装程序,默认安装即 ...

  10. Codeforces Round #611 (Div. 3) A-F简要题解

    contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...