When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A "social cluster" is a set of people who have some of their hobbies in common. You are supposed to find all the clusters.

Input Specification:

Each input file contains one test case. For each test case, the first line contains a positive integer N (<=1000), the total number of people in a social network. Hence the people are numbered from 1 to N. Then N lines follow, each gives the hobby list of a person in the format:

Ki: hi[1] hi[2] ... hi[Ki]

where Ki (>0) is the number of hobbies, and hi[j] is the index of the j-th hobby, which is an integer in [1, 1000].

Output Specification:

For each case, print in one line the total number of clusters in the network. Then in the second line, print the numbers of people in the clusters in non-increasing order. The numbers must be separated by exactly one space, and there must be no extra space at the end of the line.

Sample Input:

8
3: 2 7 10
1: 4
2: 5 3
1: 4
1: 3
1: 4
4: 6 8 1 5
1: 4

Sample Output:

3
4 3 1
 #include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int ans[][]; bool cmp(int a,int b)
{
return a > b;
} struct node
{
vector<int> child;
}; node Tree[]; int MIN = ;
int cnt = ;
bool vis[];
vector<int> Fun[];
vector<int> stu[];
void DFS(int root,int& sum)
{
for(int i = ;i < stu[root].size();++i)
{
for(int k = ;k < Fun[ stu[root][i] ].size();++k)
{
if(!vis[Fun[ stu[root][i] ][k]])
{
++sum;
vis[Fun[ stu[root][i] ][k]] = ;
DFS(Fun[ stu[root][i] ][k],sum);
}
}
}
} int main()
{
int n,num,tem;
double pri,rate;
scanf("%d",&n);
for(int i = ;i <= n ;++i)
{
scanf("%d",&num);
getchar();
for(int k = ;k < num;++k)
{
scanf("%d",&tem);
Fun[tem].push_back(i);
stu[i].push_back(tem);
}
}
vector<int> vv;
int cnt = ;;
for(int i = ;i <= n ;++i)
{
if(!vis[i])
{
int sum = ;
++cnt;
DFS(i,sum);
vv.push_back(sum);
}
}
sort(vv.begin(),vv.end(),cmp);
printf("%d\n",vv.size());
for(int i = ;i < vv.size();++i)
{
if(i == ) printf("%d",vv[]);
else printf(" %d",vv[i]);
}
printf("\n");
return ;
}

1107. Social Clusters (30)的更多相关文章

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

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

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

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

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

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

  4. PAT (Advanced Level) 1107. Social Clusters (30)

    简单并查集. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...

  5. PAT甲题题解-1107. Social Clusters (30)-PAT甲级真题(并查集)

    题意:有n个人,每个人有k个爱好,如果两个人有某个爱好相同,他们就处于同一个集合.问总共有多少个集合,以及每个集合有多少人,并按从大到小输出. 很明显,采用并查集.vis[k]标记爱好k第一次出现的人 ...

  6. 【PAT甲级】1107 Social Clusters (30分)(非递归并查集)

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

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

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

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

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

  9. 1107 Social Clusters[并查集][难]

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

随机推荐

  1. Java实现深克隆的两种方式

    序列化和依次克隆各个可变的引用类型都可以实现深克隆,但是序列化的效率并不理想 下面是两种实现深克隆的实例,并且测试类对两种方法进行了对比: 1.重写clone方法使用父类中的clone()方法实现深克 ...

  2. chrom浏览器避免弹出“确定要离开此面吗?”提示框

    一.避免弹出提示框 在网上搜了很多,答案大都是设置window.onbeforeunload=null ,但是试用之后无效. 这个问题放了两天之后返回来再次想,终于找到了答案,在此和大家分享一下: 解 ...

  3. 【JS对象、JSON字符串】之间的相互转换

    在Firefox,chrome,opera,safari,ie9,ie8等浏览器直接可以用JSON对象的stringify()和parse()方法. 1.JSON.stringify(obj)将JS对 ...

  4. CSS Sprite 图标

    HTML <body> <!-- ul.sprite>li*5>s.s-icon+a{CSS Sprite} --> <!-- 以上是Sublime Text ...

  5. Ionic之顺带APP

    1:Ionic简介 官方:我们设计ionic来帮助 web 开发人员能够像开发网站一样开发出强大的移动APP应用. ionic是一个html5开发APP的框架,在开发运行效率可以说是最好的H5框架,把 ...

  6. Android—SDCard数据存取&Environment简介

    1:Environment简介: Environment是android.os包下的一个类,谷歌官方文旦的解释为:Provides access to environment variables(提供 ...

  7. 路由器之VPN应用与配置指南

    应用背景 近日,公司需要在外人员通过直接访问连接到公司内网,实现办公等一系列操作,这个时候就需要通过配置路由器VPN实现该需求了. 无线企业路由器可以帮助中小型企业搭建高性价比.稳定的企业办公网络,灵 ...

  8. ASP.NET缓存 Cache之数据缓存

    添加 Cache[Key]=object  or Cache.Insert 移除 Cache.Remove(key) 1.将值直接写入Cache 代码如下 复制代码 HttpContext.Curre ...

  9. QtPropertyBrowser+vs2010的安装与配置(转)

    这一篇文章有些问题,后又写了一篇,地址是http://www.cnblogs.com/aminxu/p/4552410.html 转自http://blog.csdn.net/jingwenlai_s ...

  10. SQL语句新建表,同时添加主键、索引、约束

    SQL语句新建数据表   主键,索引,约束 CREATE TABLE [dbo].[T_SendInsideMessageRec]( [SendInsideMID] [uniqueidentifier ...