1107. Social Clusters (30)
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)的更多相关文章
- [并查集] 1107. Social Clusters (30)
1107. Social Clusters (30) When register on a social network, you are always asked to specify your h ...
- 1107 Social Clusters (30)(30 分)
When register on a social network, you are always asked to specify your hobbies in order to find som ...
- pat甲级 1107. Social Clusters (30)
When register on a social network, you are always asked to specify your hobbies in order to find som ...
- PAT (Advanced Level) 1107. Social Clusters (30)
简单并查集. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
- PAT甲题题解-1107. Social Clusters (30)-PAT甲级真题(并查集)
题意:有n个人,每个人有k个爱好,如果两个人有某个爱好相同,他们就处于同一个集合.问总共有多少个集合,以及每个集合有多少人,并按从大到小输出. 很明显,采用并查集.vis[k]标记爱好k第一次出现的人 ...
- 【PAT甲级】1107 Social Clusters (30分)(非递归并查集)
题意: 输入一个正整数N(<=1000),表示人数,接着输入N行每行包括一个他的爱好数量:和爱好的序号.拥有相同爱好的人们可以默认他们在同一个俱乐部,输出俱乐部的数量并从大到小输出俱乐部的人数( ...
- PAT甲级——1107 Social Clusters (并查集)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90409731 1107 Social Clusters (30 ...
- PAT-1107 Social Clusters (30 分) 并查集模板
1107 Social Clusters (30 分) When register on a social network, you are always asked to specify your ...
- 1107 Social Clusters[并查集][难]
1107 Social Clusters(30 分) When register on a social network, you are always asked to specify your h ...
随机推荐
- input输入框,回车激活按钮事件代码
<input type="text" name="输入框ID" id="输入框ID" onkeypress="if(even ...
- java 远程调试
在java 命令上加入 -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y suspend=y 配置的端口时候要保证没有被占用
- Oracle DBA需掌握的命令集锦(推荐)
第一章:日志管理 1.forcing log switches sql> alter system switch logfile; 2.forcing checkpoints sql> a ...
- web前端开发控件学习笔记之jqgrid+ztree+echarts
版权声明:本文为博主原创文章,转载请注明出处. 作为web前端初学者,今天要记录的是三个控件的使用心得,分别是表格控件jqgrid,树形控件ztree,图表控件echarts.下边分别进行描述. ...
- js中关于数据类型的转换
* 一.转化为数字*/console.log(‘123123’*1.0); /* 二.从一个值中提取另一中类型的值,并完成转化工作 */console.log(parseInt(‘1233zxhag’ ...
- 跟我学习dubbo-使用Maven构建Dubbo服务的可执行jar包(4)
Dubbo服务的运行方式: 1.使用Servlet容器运行(Tomcat.Jetty等)----不可取 缺点:增加复杂性(端口.管理) 浪费资源(内存) 官方:服务容器是一个standalone的启动 ...
- 使用MSBUILD 构建时出错 error MSB3086: Task could not find "sgen.exe" using the SdkToolsPath的解决方法
如果项目有添加有WB引用,比如引用其它网站的WEB服务等,那么VS在编译时会自动生成个 [项目名称].Serializers.dll的文件,就是把引用服务中的相关对象信息生成硬编码的程序集,以提高效率 ...
- php如何判断当前的操作系统是linux还是windows
php_uname()这个函数的意义在于返回当前PHP所运行的系统的信息,下面对这个函数详细说明一下: /** * 功能:返回当前PHP所运行的系统的信息 * @param string $mode ...
- MVC小例子
[约定胜于配置] 1. 右键Mode数据层添加新建项,用linq连接数据库 (不要在控制层上直接操控linq,要在数据层新建一个类,来对数据库进行操作) 2. 右键Mode数据层添加类,来完成对数据库 ...
- swift-自定义无限轮播图
一 前言 1.之前一直在用OC编程,最近才开始接触使用swift就发现使用OC越来越不习惯,感觉已经爱上了swift. 2.这个自定义轮播图只是对之前OC版本进行了翻译,欢迎指正. 3.我决定一步步 ...