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. Sphinx 全文检索

    什么是全文检索: 全文检索是指以文档的全部文本信息作为检索对象的一种信息检索技术.检索的对象有可能是文章的标题,也有可能是文章的作者,也有可能是文章摘要或内容. 简介: Sphinx是由俄罗斯人And ...

  2. 进程控制块的task_struct结构

    >进程控制块 在linux中进程信息存放在叫做进程控制块的数据结构中,每个进程在内核中都有⼀个进程控制块(PCB)来维护进程相关的信息,Linux内核的 进程控制块是task_struct结构体 ...

  3. tornado 杂记

    一.建立一个简单的 hello world 网页 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 import tornado.iolo ...

  4. hdu 4118 树形dp

    思路:其实就是让每一条路有尽量多的人走. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<m ...

  5. 上架第一个APP到苹果商店被拒绝5次

    - : Metadata Rejected (APP中的注册时跳转的 - 用户协议视图没有内容).Waiting For Review 6天  In Review 1天 第二次被拒绝 -- : Met ...

  6. C#调用SSIS包及读取DataReader目标

    C#调用SSIS包需要引用两个DLL .(具体位置在C盘搜索,MSDN和百度提供的路径都不太正确) Microsoft.SQLServer.ManagedDTS.dll Microsoft.SqlSe ...

  7. SQL Server高级内容之子查询和表链接

    1.子查询概念 (1)就是在查询的where子句中的判断依据是另一个查询的结果,如此就构成了一个外部的查询和一个内部的查询,这个内部的查询就是自查询. (2)自查询的分类 1)独立子查询 ->独 ...

  8. ASP.Net 类(CS)文件怎样获取Web应用程序的路径

    Web应用程序,写了一个线程CS类别,这个类别将会放于Global.asax文件中执行,主要是监控程序下某一个文件是否有异动,而作出相应警示动作,如发送邮件等. 实现运行过程中,也许会有一个情况出现, ...

  9. JAVA 模糊查询方法

    当我们需要开发一个方法用来查询数据库的时候,往往会遇到这样一个问题:就是不知道用户到底会输入什么条件,那么怎么样处理sql语句才能让我们开发的方法不管接受到什么样的条件都可以正常工作呢?这时where ...

  10. java开发命名规范(转载)

    java开发命名规范 使用前注意事项: 1.  由于Java面向对象编程的特性, 在命名时应尽量选择名词 2.  驼峰命名法(Camel-Case): 当变量名或函式名是由一个或多个单字连结在一起,而 ...