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. zend studio常见问题解答

    1.如何实现zend studio成为注册版请点击查看此链接http://www.geekso.com/ZendStudio100/ 2.如何将zend studio的默认GBK编码设置为其它编码,例 ...

  2. XE5 Android 开发数据访问手机端 解决乱码的办法

    经过测试,将sqlserver里的字段由varchar 或者char  改为  nvarchar 或者nchar 然后在手机端的clientdataset 增加字段的时候数据类型选择widestrin ...

  3. 剑指Offer19 包含min函数的栈

    /************************************************************************* > File Name: 19_MinInS ...

  4. 剑指Offer47 不用加减乘除做加法

    /************************************************************************* > File Name: 47_AddTwo ...

  5. CENTOS如何禁用ROOT本地或远程SSH登录

    下面详细描述如何禁止root登录. 禁止root本地登录 禁止root远程ssh登录 禁止root本地登录 修改/etc/pam.d/login文件增加下面一行   1 auth required p ...

  6. rfc 标准文档目录

    1.  xmpp的文档 (3920版本) https://tools.ietf.org/html/rfc3920 2. MQTT 3. SIP

  7. html form一点基础知识,实现文件上传

    form用于提交文件需要修改其entype属性. enctype属性:规定在发送表单数据之前如何对其进行编码. 默认情况,enctype的编码格式是application/x-www-form-url ...

  8. 前台传到servlet的乱码问题要怎么处理

  9. javascript事件代理(委托)

    之前有接触过事件代理,但是印象并不深刻.这次记下来加强印象. 用个大家比较常见的代码举例子: html dom结构: <ul id="ul1"> <li>0 ...

  10. Kettle 连接 oracle

    问题1:加载不了驱动 Kettle 不包含jdbc的驱程 所以需要把Ojdbc6.jar 放到 Kettle目录下 4.X: \libext\JDBC 5.x: \lib   问题2:没打开监听 症状 ...